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.
|
|
|
|
#
|
2018-07-22 18:43:38 +00:00
|
|
|
# Copyright © 2016-2018 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
|
2018-07-22 18:43:38 +00:00
|
|
|
# Copyright © 2017-2018 Maël Kervella
|
|
|
|
# Copyright © 2018 Charlie Jacomme
|
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.
|
|
|
|
|
2016-07-04 00:48:24 +00:00
|
|
|
# App de gestion des machines pour re2o
|
2016-11-11 20:10:10 +00:00
|
|
|
# Gabriel Détraz, Augustin Lemesle
|
2016-07-04 00:48:24 +00:00
|
|
|
# Gplv2
|
2018-04-14 18:19:02 +00:00
|
|
|
"""machines.views
|
|
|
|
The views for the Machines app
|
|
|
|
"""
|
2017-09-10 23:29:24 +00:00
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2016-07-04 00:48:24 +00:00
|
|
|
from django.contrib import messages
|
2016-07-09 12:59:05 +00:00
|
|
|
from django.contrib.auth.decorators import login_required, permission_required
|
2017-10-08 15:11:24 +00:00
|
|
|
from django.db.models import ProtectedError, F
|
2018-04-14 18:19:02 +00:00
|
|
|
from django.forms import modelformset_factory
|
2018-09-24 17:31:23 +00:00
|
|
|
from django.http import HttpResponse
|
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
from django.urls import reverse
|
2018-07-17 19:26:42 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2018-09-24 17:31:23 +00:00
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
2016-07-18 21:22:59 +00:00
|
|
|
from rest_framework.renderers import JSONRenderer
|
2018-04-14 18:19:02 +00:00
|
|
|
|
|
|
|
from preferences.models import GeneralOption
|
|
|
|
from re2o.acl import (
|
|
|
|
can_create,
|
|
|
|
can_edit,
|
2018-07-29 11:40:49 +00:00
|
|
|
can_view,
|
2018-04-14 18:19:02 +00:00
|
|
|
can_delete,
|
|
|
|
can_view_all,
|
|
|
|
can_delete_set,
|
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
from re2o.utils import all_active_assigned_interfaces, filter_active_interfaces
|
|
|
|
from re2o.base import SortTable, re2o_paginator
|
2018-09-24 17:31:23 +00:00
|
|
|
from re2o.views import form
|
|
|
|
from users.models import User
|
2017-10-14 10:40:22 +00:00
|
|
|
from .forms import (
|
|
|
|
NewMachineForm,
|
|
|
|
EditMachineForm,
|
|
|
|
EditInterfaceForm,
|
|
|
|
AddInterfaceForm,
|
|
|
|
MachineTypeForm,
|
|
|
|
DelMachineTypeForm,
|
|
|
|
ExtensionForm,
|
|
|
|
DelExtensionForm,
|
|
|
|
EditIpTypeForm,
|
|
|
|
IpTypeForm,
|
|
|
|
DelIpTypeForm,
|
|
|
|
DomainForm,
|
|
|
|
AliasForm,
|
|
|
|
DelAliasForm,
|
2017-10-19 23:52:38 +00:00
|
|
|
SOAForm,
|
|
|
|
DelSOAForm,
|
2017-10-14 10:40:22 +00:00
|
|
|
NsForm,
|
|
|
|
DelNsForm,
|
2017-10-15 16:35:35 +00:00
|
|
|
TxtForm,
|
|
|
|
DelTxtForm,
|
2018-06-25 14:50:45 +00:00
|
|
|
DNameForm,
|
|
|
|
DelDNameForm,
|
2017-10-14 10:40:22 +00:00
|
|
|
MxForm,
|
|
|
|
DelMxForm,
|
|
|
|
VlanForm,
|
|
|
|
DelVlanForm,
|
2018-06-23 14:39:03 +00:00
|
|
|
RoleForm,
|
|
|
|
DelRoleForm,
|
2017-10-14 10:40:22 +00:00
|
|
|
ServiceForm,
|
|
|
|
DelServiceForm,
|
2018-07-29 17:07:40 +00:00
|
|
|
SshFpForm,
|
2017-10-14 10:40:22 +00:00
|
|
|
NasForm,
|
2017-11-16 01:33:57 +00:00
|
|
|
DelNasForm,
|
|
|
|
SrvForm,
|
|
|
|
DelSrvForm,
|
2018-01-29 02:53:49 +00:00
|
|
|
Ipv6ListForm,
|
2018-04-14 18:19:02 +00:00
|
|
|
EditOuverturePortListForm,
|
2018-06-23 15:59:34 +00:00
|
|
|
EditOuverturePortConfigForm,
|
2017-10-14 10:40:22 +00:00
|
|
|
)
|
|
|
|
from .models import (
|
|
|
|
IpType,
|
|
|
|
Machine,
|
|
|
|
Interface,
|
|
|
|
MachineType,
|
|
|
|
Extension,
|
2017-10-19 23:52:38 +00:00
|
|
|
SOA,
|
2017-10-14 10:40:22 +00:00
|
|
|
Mx,
|
|
|
|
Ns,
|
|
|
|
Domain,
|
2018-06-23 14:39:03 +00:00
|
|
|
Role,
|
2017-10-14 10:40:22 +00:00
|
|
|
Service,
|
|
|
|
Service_link,
|
2018-08-09 09:39:44 +00:00
|
|
|
regen,
|
2017-10-14 10:40:22 +00:00
|
|
|
Vlan,
|
|
|
|
Nas,
|
2017-11-15 14:17:22 +00:00
|
|
|
Txt,
|
2018-06-25 14:50:45 +00:00
|
|
|
DName,
|
2017-11-16 01:33:57 +00:00
|
|
|
Srv,
|
2018-07-29 17:07:40 +00:00
|
|
|
SshFp,
|
2017-10-14 10:40:22 +00:00
|
|
|
OuverturePortList,
|
2017-11-16 01:33:57 +00:00
|
|
|
OuverturePort,
|
2018-01-29 02:53:49 +00:00
|
|
|
Ipv6List,
|
2017-10-14 10:40:22 +00:00
|
|
|
)
|
2020-04-19 21:40:09 +00:00
|
|
|
|
2016-07-04 00:48:24 +00:00
|
|
|
|
2018-04-13 22:48:44 +00:00
|
|
|
|
|
|
|
def f_type_id(is_type_tt):
|
2017-10-07 17:00:55 +00:00
|
|
|
""" The id that will be used in HTML to store the value of the field
|
|
|
|
type. Depends on the fact that type is generate using typeahead or not
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
return (
|
|
|
|
"id_Interface-machine_type_hidden"
|
|
|
|
if is_type_tt
|
|
|
|
else "id_Interface-machine_type"
|
|
|
|
)
|
2017-10-06 23:16:19 +00:00
|
|
|
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2018-04-14 18:19:02 +00:00
|
|
|
def generate_ipv4_choices(form_obj):
|
2017-10-14 13:27:56 +00:00
|
|
|
""" Generate the parameter choices for the massive_bootstrap_form tag
|
2017-10-07 17:00:55 +00:00
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
f_ipv4 = form_obj.fields["ipv4"]
|
2017-10-07 17:00:55 +00:00
|
|
|
used_mtype_id = []
|
2018-09-24 17:31:23 +00:00
|
|
|
choices = '{"":[{key:"",value:"' + _("Select a machine type first.") + '"}'
|
2017-10-07 17:00:55 +00:00
|
|
|
mtype_id = -1
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
for ip in f_ipv4.queryset.annotate(mtype_id=F("ip_type__machinetype__id")).order_by(
|
|
|
|
"mtype_id", "id"
|
|
|
|
):
|
2018-04-13 22:48:44 +00:00
|
|
|
if mtype_id != ip.mtype_id:
|
2017-10-07 17:00:55 +00:00
|
|
|
mtype_id = ip.mtype_id
|
|
|
|
used_mtype_id.append(mtype_id)
|
2017-10-08 00:48:32 +00:00
|
|
|
choices += '],"{t}":[{{key:"",value:"{v}"}},'.format(
|
2019-11-04 16:55:03 +00:00
|
|
|
t=mtype_id, v=f_ipv4.empty_label or '""'
|
2017-10-08 00:48:32 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
choices += '{{key:{k},value:"{v}"}},'.format(k=ip.id, v=ip.ipv4)
|
2017-10-07 17:00:55 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
for t in form_obj.fields["machine_type"].queryset.exclude(id__in=used_mtype_id):
|
2018-09-24 17:31:23 +00:00
|
|
|
choices += '], "' + str(t.id) + '": ['
|
2017-10-07 17:00:55 +00:00
|
|
|
choices += '{key: "", value: "' + str(f_ipv4.empty_label) + '"},'
|
2019-11-04 16:55:03 +00:00
|
|
|
choices += "]}"
|
2017-10-07 17:00:55 +00:00
|
|
|
return choices
|
|
|
|
|
2018-04-13 22:48:44 +00:00
|
|
|
|
|
|
|
def generate_ipv4_engine(is_type_tt):
|
2017-10-14 13:27:56 +00:00
|
|
|
""" Generate the parameter engine for the massive_bootstrap_form tag
|
2017-10-07 17:00:55 +00:00
|
|
|
"""
|
2017-10-08 00:48:32 +00:00
|
|
|
return (
|
2019-11-04 16:55:03 +00:00
|
|
|
"new Bloodhound( {{"
|
2018-07-17 19:26:42 +00:00
|
|
|
'datumTokenizer: Bloodhound.tokenizers.obj.whitespace( "value" ),'
|
2019-11-04 16:55:03 +00:00
|
|
|
"queryTokenizer: Bloodhound.tokenizers.whitespace,"
|
2019-03-03 16:28:33 +00:00
|
|
|
'local: choices_ipv4[ $( "#{machine_type_id}" ).val() ],'
|
2019-11-04 16:55:03 +00:00
|
|
|
"identify: function( obj ) {{ return obj.key; }}"
|
|
|
|
"}} )"
|
|
|
|
).format(machine_type_id=f_type_id(is_type_tt))
|
2017-10-07 17:00:55 +00:00
|
|
|
|
2018-04-13 22:48:44 +00:00
|
|
|
|
|
|
|
def generate_ipv4_match_func(is_type_tt):
|
2017-10-14 13:27:56 +00:00
|
|
|
""" Generate the parameter match_func for the massive_bootstrap_form tag
|
2017-10-07 17:00:55 +00:00
|
|
|
"""
|
2017-10-08 00:48:32 +00:00
|
|
|
return (
|
2019-11-04 16:55:03 +00:00
|
|
|
"function(q, sync) {{"
|
2018-07-17 19:26:42 +00:00
|
|
|
'if (q === "") {{'
|
2019-03-03 16:28:33 +00:00
|
|
|
'var first = choices_ipv4[$("#{machine_type_id}").val()].slice(0, 5);'
|
2019-11-04 16:55:03 +00:00
|
|
|
"first = first.map( function (obj) {{ return obj.key; }} );"
|
|
|
|
"sync(engine_ipv4.get(first));"
|
|
|
|
"}} else {{"
|
|
|
|
"engine_ipv4.search(q, sync);"
|
|
|
|
"}}"
|
|
|
|
"}}"
|
|
|
|
).format(machine_type_id=f_type_id(is_type_tt))
|
2017-10-06 23:16:19 +00:00
|
|
|
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2018-04-14 18:19:02 +00:00
|
|
|
def generate_ipv4_mbf_param(form_obj, is_type_tt):
|
2017-10-14 13:27:56 +00:00
|
|
|
""" Generate all the parameters to use with the massive_bootstrap_form
|
2017-10-07 17:00:55 +00:00
|
|
|
tag """
|
2019-11-04 16:55:03 +00:00
|
|
|
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)]}
|
|
|
|
i_gen_select = {"ipv4": False}
|
2017-10-14 13:27:56 +00:00
|
|
|
i_mbf_param = {
|
2019-11-04 16:55:03 +00:00
|
|
|
"choices": i_choices,
|
|
|
|
"engine": i_engine,
|
|
|
|
"match_func": i_match_func,
|
|
|
|
"update_on": i_update_on,
|
|
|
|
"gen_select": i_gen_select,
|
2017-10-07 17:00:55 +00:00
|
|
|
}
|
2017-10-14 13:27:56 +00:00
|
|
|
return i_mbf_param
|
2017-10-06 23:16:19 +00:00
|
|
|
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Machine)
|
2017-12-09 01:15:11 +00:00
|
|
|
@can_edit(User)
|
2018-04-15 01:00:05 +00:00
|
|
|
def new_machine(request, user, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create machines.
|
2017-11-28 22:33:47 +00:00
|
|
|
|
2020-04-29 22:17:01 +00:00
|
|
|
Creates the object, the underlying interface and domain objects from model
|
|
|
|
forms. Too complex, should be simplified.
|
|
|
|
"""
|
2018-01-08 22:57:19 +00:00
|
|
|
machine = NewMachineForm(request.POST or None, user=request.user)
|
2019-11-04 16:55:03 +00:00
|
|
|
interface = AddInterfaceForm(request.POST or None, user=request.user)
|
2020-01-24 22:49:43 +00:00
|
|
|
domain = DomainForm(request.POST or None, user=user, initial={'name': user.get_next_domain_name()})
|
2017-08-01 04:57:56 +00:00
|
|
|
if machine.is_valid() and interface.is_valid():
|
2018-04-14 18:19:02 +00:00
|
|
|
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
|
2017-08-01 04:57:56 +00:00
|
|
|
if domain.is_valid():
|
2017-01-13 21:25:03 +00:00
|
|
|
new_domain = domain.save(commit=False)
|
2018-04-14 18:19:02 +00:00
|
|
|
new_machine_obj.save()
|
|
|
|
new_interface_obj.machine = new_machine_obj
|
|
|
|
new_interface_obj.save()
|
|
|
|
new_domain.interface_parent = new_interface_obj
|
2018-03-31 15:18:39 +00:00
|
|
|
new_domain.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The machine was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(user.id)}))
|
2017-11-28 22:33:47 +00:00
|
|
|
i_mbf_param = generate_ipv4_mbf_param(interface, False)
|
|
|
|
return form(
|
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"machineform": machine,
|
|
|
|
"interfaceform": interface,
|
|
|
|
"domainform": domain,
|
|
|
|
"i_mbf_param": i_mbf_param,
|
2019-11-16 14:07:15 +00:00
|
|
|
"action_name": _("Add"),
|
2017-11-28 22:33:47 +00:00
|
|
|
},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2017-11-28 22:33:47 +00:00
|
|
|
)
|
2016-07-04 00:48:24 +00:00
|
|
|
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Interface)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_interface(request, interface_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit interfaces.
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2020-04-29 22:17:01 +00:00
|
|
|
The values a user can change depends on their rights.
|
|
|
|
"""
|
2017-12-30 00:48:23 +00:00
|
|
|
machine_form = EditMachineForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=interface_instance.machine, user=request.user
|
2017-12-30 00:48:23 +00:00
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
interface_form = EditInterfaceForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=interface_instance, user=request.user
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
domain_form = DomainForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=interface_instance.domain, user=request.user
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
if machine_form.is_valid() and interface_form.is_valid() and domain_form.is_valid():
|
2018-04-14 18:19:02 +00:00
|
|
|
new_machine_obj = machine_form.save(commit=False)
|
|
|
|
new_interface_obj = interface_form.save(commit=False)
|
|
|
|
new_domain_obj = domain_form.save(commit=False)
|
2018-03-31 22:06:44 +00:00
|
|
|
if machine_form.changed_data:
|
2018-04-14 18:19:02 +00:00
|
|
|
new_machine_obj.save()
|
2018-03-31 22:06:44 +00:00
|
|
|
if interface_form.changed_data:
|
2018-04-14 18:19:02 +00:00
|
|
|
new_interface_obj.save()
|
2019-09-21 22:34:10 +00:00
|
|
|
new_domain_obj.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The machine was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse(
|
|
|
|
"users:profil",
|
|
|
|
kwargs={"userid": str(interface_instance.machine.user.id)},
|
|
|
|
)
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
i_mbf_param = generate_ipv4_mbf_param(interface_form, False)
|
|
|
|
return form(
|
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"machineform": machine_form,
|
|
|
|
"interfaceform": interface_form,
|
|
|
|
"domainform": domain_form,
|
|
|
|
"i_mbf_param": i_mbf_param,
|
|
|
|
"action_name": _("Edit"),
|
2018-04-13 22:48:44 +00:00
|
|
|
},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-04 00:48:24 +00:00
|
|
|
|
2016-07-18 03:30:35 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_delete(Machine)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_machine(request, machine, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete machines, and the interfaces in cascade."""
|
2016-07-18 16:37:52 +00:00
|
|
|
if request.method == "POST":
|
2018-03-31 15:18:39 +00:00
|
|
|
machine.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The machine was deleted."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("users:profil", kwargs={"userid": str(machine.user.id)})
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"objet": machine, "objet_name": _("machine")}, "machines/delete.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-18 03:30:35 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Interface)
|
2017-12-09 01:15:11 +00:00
|
|
|
@can_edit(Machine)
|
2018-04-15 01:00:05 +00:00
|
|
|
def new_interface(request, machine, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create interfaces and the associated domains related to a
|
|
|
|
machine.
|
|
|
|
"""
|
2018-01-08 22:57:19 +00:00
|
|
|
interface_form = AddInterfaceForm(request.POST or None, user=request.user)
|
2020-01-24 22:49:43 +00:00
|
|
|
domain_form = DomainForm(request.POST or None, user=request.user, initial={'name': machine.user.get_next_domain_name()})
|
2017-08-01 04:57:56 +00:00
|
|
|
if interface_form.is_valid():
|
2018-04-14 18:19:02 +00:00
|
|
|
new_interface_obj = interface_form.save(commit=False)
|
|
|
|
domain_form.instance.interface_parent = new_interface_obj
|
|
|
|
new_interface_obj.machine = machine
|
2017-08-01 04:57:56 +00:00
|
|
|
if domain_form.is_valid():
|
2018-04-14 18:19:02 +00:00
|
|
|
new_domain_obj = domain_form.save(commit=False)
|
|
|
|
new_interface_obj.save()
|
|
|
|
new_domain_obj.interface_parent = new_interface_obj
|
|
|
|
new_domain_obj.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The interface was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("users:profil", kwargs={"userid": str(machine.user.id)})
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
i_mbf_param = generate_ipv4_mbf_param(interface_form, False)
|
|
|
|
return form(
|
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"interfaceform": interface_form,
|
|
|
|
"domainform": domain_form,
|
|
|
|
"i_mbf_param": i_mbf_param,
|
2019-11-16 14:07:15 +00:00
|
|
|
"action_name": _("Add"),
|
2018-04-13 22:48:44 +00:00
|
|
|
},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-04 00:48:24 +00:00
|
|
|
|
2016-07-18 03:30:35 +00:00
|
|
|
@login_required
|
2017-12-09 01:15:11 +00:00
|
|
|
@can_delete(Interface)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_interface(request, interface, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete interfaces, and the domains in cascade."""
|
2016-07-18 16:37:52 +00:00
|
|
|
if request.method == "POST":
|
2016-12-14 17:09:24 +00:00
|
|
|
machine = interface.machine
|
2018-03-31 15:18:39 +00:00
|
|
|
interface.delete()
|
|
|
|
if not machine.interface_set.all():
|
|
|
|
machine.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The interface was deleted."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("users:profil", kwargs={"userid": str(request.user.id)})
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"objet": interface, "objet_name": _("interface")}, "machines/delete.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-18 03:30:35 +00:00
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(Ipv6List)
|
|
|
|
@can_edit(Interface)
|
2018-04-15 01:00:05 +00:00
|
|
|
def new_ipv6list(request, interface, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create IPv6 addresses lists."""
|
2018-01-30 02:01:06 +00:00
|
|
|
ipv6list_instance = Ipv6List(interface=interface)
|
2018-04-13 22:48:44 +00:00
|
|
|
ipv6 = Ipv6ListForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=ipv6list_instance, user=request.user
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2018-01-29 02:53:49 +00:00
|
|
|
if ipv6.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
ipv6.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The IPv6 addresses list was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("machines:index-ipv6", kwargs={"interfaceid": str(interface.id)})
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"ipv6form": ipv6, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(Ipv6List)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_ipv6list(request, ipv6list_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit IPv6 addresses lists."""
|
2018-04-13 22:48:44 +00:00
|
|
|
ipv6 = Ipv6ListForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=ipv6list_instance, user=request.user
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2018-01-29 02:53:49 +00:00
|
|
|
if ipv6.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if ipv6.changed_data:
|
|
|
|
ipv6.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The IPv6 addresses list was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse(
|
|
|
|
"machines:index-ipv6",
|
|
|
|
kwargs={"interfaceid": str(ipv6list_instance.interface.id)},
|
|
|
|
)
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"ipv6form": ipv6, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(Ipv6List)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_ipv6list(request, ipv6list, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete IPv6 addresses lists."""
|
2018-01-29 02:53:49 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
interfaceid = ipv6list.interface.id
|
2018-03-31 15:18:39 +00:00
|
|
|
ipv6list.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The IPv6 addresses list was deleted."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("machines:index-ipv6", kwargs={"interfaceid": str(interfaceid)})
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"objet": ipv6list, "objet_name": _("IPv6 addresses list")}, "machines/delete.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
|
2018-06-23 15:59:34 +00:00
|
|
|
@login_required
|
2018-07-29 17:07:40 +00:00
|
|
|
@can_create(SshFp)
|
2018-06-23 15:59:34 +00:00
|
|
|
@can_edit(Machine)
|
2018-07-29 17:07:40 +00:00
|
|
|
def new_sshfp(request, machine, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create SSHFP records associated with machines."""
|
2018-07-29 17:07:40 +00:00
|
|
|
sshfp_instance = SshFp(machine=machine)
|
2019-11-04 16:55:03 +00:00
|
|
|
sshfp = SshFpForm(request.POST or None, instance=sshfp_instance)
|
2018-07-29 17:07:40 +00:00
|
|
|
if sshfp.is_valid():
|
|
|
|
sshfp.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The SSHFP record was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("machines:index-sshfp", kwargs={"machineid": str(machine.id)})
|
|
|
|
)
|
2018-06-23 15:59:34 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"sshfpform": sshfp, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-06-23 15:59:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2018-07-29 17:07:40 +00:00
|
|
|
@can_edit(SshFp)
|
|
|
|
def edit_sshfp(request, sshfp_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit SSHFP records."""
|
2019-11-04 16:55:03 +00:00
|
|
|
sshfp = SshFpForm(request.POST or None, instance=sshfp_instance)
|
2018-07-29 17:07:40 +00:00
|
|
|
if sshfp.is_valid():
|
|
|
|
if sshfp.changed_data:
|
|
|
|
sshfp.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The SSHFP record was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse(
|
|
|
|
"machines:index-sshfp",
|
|
|
|
kwargs={"machineid": str(sshfp_instance.machine.id)},
|
|
|
|
)
|
|
|
|
)
|
2018-06-23 15:59:34 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"sshfpform": sshfp, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-06-23 15:59:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2018-07-29 17:07:40 +00:00
|
|
|
@can_delete(SshFp)
|
|
|
|
def del_sshfp(request, sshfp, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete SSHFP records."""
|
2018-06-23 15:59:34 +00:00
|
|
|
if request.method == "POST":
|
2018-07-29 17:07:40 +00:00
|
|
|
machineid = sshfp.machine.id
|
|
|
|
sshfp.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The SSHFP record was deleted."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("machines:index-sshfp", kwargs={"machineid": str(machineid)})
|
|
|
|
)
|
2018-06-23 15:59:34 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"objet": sshfp, "objet_name": _("SSHFP record")}, "machines/delete.html", request
|
2018-06-23 15:59:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(IpType)
|
2016-10-22 22:55:58 +00:00
|
|
|
def add_iptype(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create IP ranges.
|
2017-11-29 00:53:32 +00:00
|
|
|
|
2020-04-29 22:17:01 +00:00
|
|
|
The view function is simple, the intelligence is in the model.
|
|
|
|
"""
|
2016-10-22 22:55:58 +00:00
|
|
|
iptype = IpTypeForm(request.POST or None)
|
|
|
|
if iptype.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
iptype.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The IP type was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-iptype"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"iptypeform": iptype, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(IpType)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_iptype(request, iptype_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit IP ranges.
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2020-04-29 22:17:01 +00:00
|
|
|
Changing the size of the range is not possible to prevent inconsistency.
|
|
|
|
"""
|
2017-07-21 03:06:53 +00:00
|
|
|
iptype = EditIpTypeForm(request.POST or None, instance=iptype_instance)
|
2016-10-22 22:55:58 +00:00
|
|
|
if iptype.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if iptype.changed_data:
|
|
|
|
iptype.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The IP type was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-iptype"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"iptypeform": iptype, "action_name": _("Edit")},
|
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(IpType)
|
|
|
|
def del_iptype(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete IP ranges.
|
|
|
|
|
|
|
|
Deletes the related IP objects.
|
|
|
|
"""
|
2017-12-13 17:31:13 +00:00
|
|
|
iptype = DelIpTypeForm(request.POST or None, instances=instances)
|
2016-10-22 22:55:58 +00:00
|
|
|
if iptype.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
iptype_dels = iptype.cleaned_data["iptypes"]
|
2016-10-22 22:55:58 +00:00
|
|
|
for iptype_del in iptype_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
iptype_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The IP type was deleted."))
|
2016-10-22 22:55:58 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The IP type %s is assigned to at least one machine,"
|
|
|
|
" you can't delete it."
|
|
|
|
)
|
|
|
|
% iptype_del
|
|
|
|
),
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-iptype"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"iptypeform": iptype, "action_name": _("Delete")},
|
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(MachineType)
|
2016-07-07 11:19:03 +00:00
|
|
|
def add_machinetype(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create machine types."""
|
2016-07-07 11:19:03 +00:00
|
|
|
machinetype = MachineTypeForm(request.POST or None)
|
|
|
|
if machinetype.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
machinetype.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The machine type was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-machinetype"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"machinetypeform": machinetype, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-07 11:19:03 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(MachineType)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_machinetype(request, machinetype_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit machine types."""
|
2019-11-04 16:55:03 +00:00
|
|
|
machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance)
|
2016-07-08 00:48:44 +00:00
|
|
|
if machinetype.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if machinetype.changed_data:
|
|
|
|
machinetype.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The machine type was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-machinetype"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"machinetypeform": machinetype, "action_name": _("Edit")},
|
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-08 00:48:44 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(MachineType)
|
|
|
|
def del_machinetype(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete machines types."""
|
2017-12-13 17:31:13 +00:00
|
|
|
machinetype = DelMachineTypeForm(request.POST or None, instances=instances)
|
2016-07-07 11:19:03 +00:00
|
|
|
if machinetype.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
machinetype_dels = machinetype.cleaned_data["machinetypes"]
|
2016-07-07 11:19:03 +00:00
|
|
|
for machinetype_del in machinetype_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
machinetype_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The machine type was deleted."))
|
2016-07-07 11:19:03 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The machine type %s is assigned to at least one"
|
|
|
|
" machine, you can't delete it."
|
|
|
|
)
|
|
|
|
% machinetype_del
|
|
|
|
),
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-machinetype"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"machinetypeform": machinetype, "action_name": _("Delete")},
|
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-07 11:19:03 +00:00
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Extension)
|
2016-07-08 15:54:06 +00:00
|
|
|
def add_extension(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create extensions."""
|
2016-07-08 15:54:06 +00:00
|
|
|
extension = ExtensionForm(request.POST or None)
|
|
|
|
if extension.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
extension.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The extension was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"extensionform": extension, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Extension)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_extension(request, extension_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit extensions."""
|
2019-11-04 16:55:03 +00:00
|
|
|
extension = ExtensionForm(request.POST or None, instance=extension_instance)
|
2016-07-08 15:54:06 +00:00
|
|
|
if extension.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if extension.changed_data:
|
|
|
|
extension.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The extension was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"extensionform": extension, "action_name": _("Edit")},
|
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(Extension)
|
|
|
|
def del_extension(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete extensions."""
|
2017-12-13 17:31:13 +00:00
|
|
|
extension = DelExtensionForm(request.POST or None, instances=instances)
|
2016-07-08 15:54:06 +00:00
|
|
|
if extension.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
extension_dels = extension.cleaned_data["extensions"]
|
2016-07-08 15:54:06 +00:00
|
|
|
for extension_del in extension_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
extension_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The extension was deleted."))
|
2016-07-08 15:54:06 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The extension %s is assigned to at least one machine"
|
|
|
|
" type, you can't delete it." % extension_del
|
|
|
|
)
|
|
|
|
),
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"extensionform": extension, "action_name": _("Delete")},
|
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
|
2017-10-19 23:52:38 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(SOA)
|
2017-10-19 23:52:38 +00:00
|
|
|
def add_soa(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create SOA records."""
|
2017-10-19 23:52:38 +00:00
|
|
|
soa = SOAForm(request.POST or None)
|
|
|
|
if soa.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
soa.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The SOA record was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"soaform": soa, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-10-19 23:52:38 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(SOA)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_soa(request, soa_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit SOA records."""
|
2017-10-19 23:52:38 +00:00
|
|
|
soa = SOAForm(request.POST or None, instance=soa_instance)
|
|
|
|
if soa.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if soa.changed_data:
|
|
|
|
soa.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The SOA record was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"soaform": soa, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-10-19 23:52:38 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(SOA)
|
|
|
|
def del_soa(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete SOA records."""
|
2017-12-13 17:31:13 +00:00
|
|
|
soa = DelSOAForm(request.POST or None, instances=instances)
|
2017-10-19 23:52:38 +00:00
|
|
|
if soa.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
soa_dels = soa.cleaned_data["soa"]
|
2017-10-19 23:52:38 +00:00
|
|
|
for soa_del in soa_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
soa_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The SOA record was deleted."))
|
2017-10-19 23:52:38 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
2019-11-04 16:55:03 +00:00
|
|
|
request, (_("Error: the SOA record %s can't be deleted.") % soa_del)
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"soaform": soa, "action_name": _("Delete")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-10-19 23:52:38 +00:00
|
|
|
|
2016-11-19 16:44:43 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Mx)
|
2016-11-19 16:44:43 +00:00
|
|
|
def add_mx(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create MX records."""
|
2016-11-19 16:44:43 +00:00
|
|
|
mx = MxForm(request.POST or None)
|
|
|
|
if mx.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
mx.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The MX record was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"mxform": mx, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-11-19 16:44:43 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Mx)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_mx(request, mx_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit MX records."""
|
2016-11-19 16:44:43 +00:00
|
|
|
mx = MxForm(request.POST or None, instance=mx_instance)
|
|
|
|
if mx.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if mx.changed_data:
|
|
|
|
mx.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The MX record was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"mxform": mx, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-11-19 16:44:43 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(Mx)
|
|
|
|
def del_mx(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete MX records."""
|
2017-12-13 17:31:13 +00:00
|
|
|
mx = DelMxForm(request.POST or None, instances=instances)
|
2016-11-19 16:44:43 +00:00
|
|
|
if mx.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
mx_dels = mx.cleaned_data["mx"]
|
2016-11-19 16:44:43 +00:00
|
|
|
for mx_del in mx_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
mx_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The MX record was deleted."))
|
2016-11-19 16:44:43 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
2019-11-04 16:55:03 +00:00
|
|
|
request, (_("Error: the MX record %s can't be deleted.") % mx_del)
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"mxform": mx, "action_name": _("Delete")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-11-19 16:44:43 +00:00
|
|
|
|
2016-11-19 17:21:05 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Ns)
|
2016-11-19 17:21:05 +00:00
|
|
|
def add_ns(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create NS records."""
|
2016-11-19 17:21:05 +00:00
|
|
|
ns = NsForm(request.POST or None)
|
|
|
|
if ns.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
ns.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The NS record was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"nsform": ns, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-11-19 17:21:05 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Ns)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_ns(request, ns_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit NS records."""
|
2016-11-19 17:21:05 +00:00
|
|
|
ns = NsForm(request.POST or None, instance=ns_instance)
|
|
|
|
if ns.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if ns.changed_data:
|
|
|
|
ns.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The NS record was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"nsform": ns, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-11-19 17:21:05 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(Ns)
|
|
|
|
def del_ns(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete NS records."""
|
2020-01-24 20:37:24 +00:00
|
|
|
nss = DelNsForm(request.POST or None, instances=instances)
|
|
|
|
if nss.is_valid():
|
|
|
|
ns_dels = nss.cleaned_data["nss"]
|
2016-11-19 17:21:05 +00:00
|
|
|
for ns_del in ns_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
ns_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The NS record was deleted."))
|
2016-11-19 17:21:05 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
2019-11-04 16:55:03 +00:00
|
|
|
request, (_("Error: the NS record %s can't be deleted.") % ns_del)
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2020-01-24 20:37:24 +00:00
|
|
|
{"nsform": nss, "action_name": _("Delete")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2018-06-25 14:50:45 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(DName)
|
|
|
|
def add_dname(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create DNAME records."""
|
2018-06-25 14:50:45 +00:00
|
|
|
dname = DNameForm(request.POST or None)
|
|
|
|
if dname.is_valid():
|
|
|
|
dname.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The DNAME record was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-06-25 14:50:45 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"dnameform": dname, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-06-25 14:50:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(DName)
|
|
|
|
def edit_dname(request, dname_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit DNAME records."""
|
2018-06-25 14:50:45 +00:00
|
|
|
dname = DNameForm(request.POST or None, instance=dname_instance)
|
|
|
|
if dname.is_valid():
|
|
|
|
if dname.changed_data:
|
|
|
|
dname.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The DNAME record was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-06-25 14:50:45 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"dnameform": dname, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-06-25 14:50:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete_set(DName)
|
|
|
|
def del_dname(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete DNAME records."""
|
2018-06-25 14:50:45 +00:00
|
|
|
dname = DelDNameForm(request.POST or None, instances=instances)
|
|
|
|
if dname.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
dname_dels = dname.cleaned_data["dname"]
|
2018-06-25 14:50:45 +00:00
|
|
|
for dname_del in dname_dels:
|
|
|
|
try:
|
|
|
|
dname_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The DNAME record was deleted."))
|
2018-06-25 14:50:45 +00:00
|
|
|
except ProtectedError:
|
|
|
|
messages.error(
|
2018-09-24 17:31:23 +00:00
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
_("Error: the DNAME record %s can't be deleted.") % dname_del,
|
2018-06-25 14:50:45 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-06-25 14:50:45 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"dnameform": dname, "action_name": _("Delete")},
|
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-06-25 14:50:45 +00:00
|
|
|
)
|
|
|
|
|
2016-11-19 17:21:05 +00:00
|
|
|
|
2017-09-05 16:18:41 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Txt)
|
2017-10-11 21:33:21 +00:00
|
|
|
def add_txt(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create TXT records."""
|
2017-10-11 21:33:21 +00:00
|
|
|
txt = TxtForm(request.POST or None)
|
|
|
|
if txt.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
txt.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The TXT record was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"txtform": txt, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-09-05 16:18:41 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Txt)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_txt(request, txt_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit TXT records."""
|
2017-10-11 21:33:21 +00:00
|
|
|
txt = TxtForm(request.POST or None, instance=txt_instance)
|
|
|
|
if txt.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if txt.changed_data:
|
|
|
|
txt.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The TXT record was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"txtform": txt, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-09-05 16:18:41 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(Txt)
|
|
|
|
def del_txt(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete TXT records."""
|
2017-12-13 17:31:13 +00:00
|
|
|
txt = DelTxtForm(request.POST or None, instances=instances)
|
2017-10-11 21:33:21 +00:00
|
|
|
if txt.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
txt_dels = txt.cleaned_data["txt"]
|
2017-10-11 21:33:21 +00:00
|
|
|
for txt_del in txt_dels:
|
2017-09-05 16:18:41 +00:00
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
txt_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The TXT record was deleted."))
|
2017-09-05 16:18:41 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
2019-11-04 16:55:03 +00:00
|
|
|
request, (_("Error: the TXT record %s can't be deleted.") % txt_del)
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"txtform": txt, "action_name": _("Delete")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-09-05 16:18:41 +00:00
|
|
|
|
2017-11-16 01:33:57 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Srv)
|
2017-11-16 01:33:57 +00:00
|
|
|
def add_srv(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create SRV records."""
|
2017-11-16 01:33:57 +00:00
|
|
|
srv = SrvForm(request.POST or None)
|
|
|
|
if srv.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
srv.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The SRV record was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"srvform": srv, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-11-16 01:33:57 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Srv)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_srv(request, srv_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit SRV records."""
|
2017-11-16 01:33:57 +00:00
|
|
|
srv = SrvForm(request.POST or None, instance=srv_instance)
|
|
|
|
if srv.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if srv.changed_data:
|
|
|
|
srv.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The SRV record was edited."))
|
2020-04-26 23:38:29 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"srvform": srv, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-11-16 01:33:57 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(Srv)
|
|
|
|
def del_srv(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete SRV records."""
|
2017-12-13 17:31:13 +00:00
|
|
|
srv = DelSrvForm(request.POST or None, instances=instances)
|
2017-11-16 01:33:57 +00:00
|
|
|
if srv.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
srv_dels = srv.cleaned_data["srv"]
|
2017-11-16 01:33:57 +00:00
|
|
|
for srv_del in srv_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
srv_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The SRV record was deleted."))
|
2017-11-16 01:33:57 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
2019-11-04 16:55:03 +00:00
|
|
|
request, (_("Error: the SRV record %s can't be deleted.") % srv_del)
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-extension"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"srvform": srv, "action_name": _("Delete")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-11-16 01:33:57 +00:00
|
|
|
|
2016-11-19 20:15:43 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Domain)
|
2017-12-09 01:15:11 +00:00
|
|
|
@can_edit(Interface)
|
|
|
|
def add_alias(request, interface, interfaceid):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create aliases."""
|
2017-12-29 00:42:00 +00:00
|
|
|
alias = AliasForm(request.POST or None, user=request.user)
|
2016-11-19 20:15:43 +00:00
|
|
|
if alias.is_valid():
|
|
|
|
alias = alias.save(commit=False)
|
2016-12-24 19:04:53 +00:00
|
|
|
alias.cname = interface.domain
|
2018-03-31 15:18:39 +00:00
|
|
|
alias.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The alias was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("machines:index-alias", kwargs={"interfaceid": str(interfaceid)})
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"aliasform": alias, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-11-19 20:15:43 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Domain)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_alias(request, domain_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit aliases records."""
|
2019-11-04 16:55:03 +00:00
|
|
|
alias = AliasForm(request.POST or None, instance=domain_instance, user=request.user)
|
2016-11-19 20:15:43 +00:00
|
|
|
if alias.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if alias.changed_data:
|
|
|
|
domain_instance = alias.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The alias was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse(
|
|
|
|
"machines:index-alias",
|
|
|
|
kwargs={"interfaceid": str(domain_instance.cname.interface_parent.id)},
|
|
|
|
)
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"aliasform": alias, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-11-19 20:15:43 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-09 01:15:11 +00:00
|
|
|
@can_edit(Interface)
|
|
|
|
def del_alias(request, interface, interfaceid):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete aliases records."""
|
2016-11-19 20:15:43 +00:00
|
|
|
alias = DelAliasForm(request.POST or None, interface=interface)
|
|
|
|
if alias.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
alias_dels = alias.cleaned_data["alias"]
|
2016-11-19 20:15:43 +00:00
|
|
|
for alias_del in alias_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
alias_del.delete()
|
2019-11-04 16:55:03 +00:00
|
|
|
messages.success(request, _("The alias %s was deleted.") % alias_del)
|
2016-11-19 20:15:43 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
2019-11-04 16:55:03 +00:00
|
|
|
request, (_("Error: the alias %s can't be deleted.") % alias_del)
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("machines:index-alias", kwargs={"interfaceid": str(interfaceid)})
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"aliasform": alias, "action_name": _("Delete")},
|
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2016-11-19 20:15:43 +00:00
|
|
|
|
2017-08-08 04:56:19 +00:00
|
|
|
|
2018-06-23 14:39:03 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(Role)
|
|
|
|
def add_role(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create roles."""
|
2018-06-23 14:39:03 +00:00
|
|
|
role = RoleForm(request.POST or None)
|
|
|
|
if role.is_valid():
|
|
|
|
role.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The role was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-role"))
|
2018-06-23 14:39:03 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"roleform": role, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-06-23 14:39:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(Role)
|
|
|
|
def edit_role(request, role_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit roles."""
|
2018-06-23 14:39:03 +00:00
|
|
|
role = RoleForm(request.POST or None, instance=role_instance)
|
|
|
|
if role.is_valid():
|
|
|
|
if role.changed_data:
|
|
|
|
role.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The role was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-role"))
|
2018-06-23 14:39:03 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"roleform": role, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-06-23 14:39:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete_set(Role)
|
|
|
|
def del_role(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete roles."""
|
2018-06-23 14:39:03 +00:00
|
|
|
role = DelRoleForm(request.POST or None, instances=instances)
|
|
|
|
if role.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
role_dels = role.cleaned_data["role"]
|
2018-06-23 14:39:03 +00:00
|
|
|
for role_del in role_dels:
|
|
|
|
try:
|
|
|
|
role_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The role was deleted."))
|
2018-06-23 14:39:03 +00:00
|
|
|
except ProtectedError:
|
|
|
|
messages.error(
|
2019-11-04 16:55:03 +00:00
|
|
|
request, (_("Error: the role %s can't be deleted.") % role_del)
|
2018-06-23 14:39:03 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-role"))
|
2018-06-23 14:39:03 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"roleform": role, "action_name": _("Delete")}, "machines/machine.html", request
|
2018-06-23 14:39:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-08-08 04:56:19 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Service)
|
2017-08-08 04:56:19 +00:00
|
|
|
def add_service(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create services."""
|
2017-08-08 04:56:19 +00:00
|
|
|
service = ServiceForm(request.POST or None)
|
|
|
|
if service.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
service.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The service was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-service"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"serviceform": service, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-08-08 04:56:19 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Service)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_service(request, service_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit services."""
|
2017-08-08 04:56:19 +00:00
|
|
|
service = ServiceForm(request.POST or None, instance=service_instance)
|
|
|
|
if service.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if service.changed_data:
|
|
|
|
service.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The service was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-service"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"serviceform": service, "action_name": _("Edit")},
|
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-08-08 04:56:19 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(Service)
|
|
|
|
def del_service(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete services."""
|
2017-12-13 17:31:13 +00:00
|
|
|
service = DelServiceForm(request.POST or None, instances=instances)
|
2017-08-08 04:56:19 +00:00
|
|
|
if service.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
service_dels = service.cleaned_data["service"]
|
2017-08-08 04:56:19 +00:00
|
|
|
for service_del in service_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
service_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The service was deleted."))
|
2017-08-08 04:56:19 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(_("Error: the service %s can't be deleted.") % service_del),
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-service"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"serviceform": service, "action_name": _("Delete")},
|
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2018-09-24 17:31:23 +00:00
|
|
|
|
2018-08-09 09:39:44 +00:00
|
|
|
@login_required
|
|
|
|
@can_edit(Service)
|
2018-09-24 17:31:23 +00:00
|
|
|
def regen_service(request, service, **_kwargs):
|
2018-08-09 09:39:44 +00:00
|
|
|
"""Ask for a regen of the service"""
|
|
|
|
|
|
|
|
regen(service)
|
|
|
|
return index_service(request)
|
|
|
|
|
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Vlan)
|
2017-08-26 13:10:18 +00:00
|
|
|
def add_vlan(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create VLANs."""
|
2017-08-26 13:10:18 +00:00
|
|
|
vlan = VlanForm(request.POST or None)
|
|
|
|
if vlan.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
vlan.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The VLAN was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-vlan"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"vlanform": vlan, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Vlan)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_vlan(request, vlan_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit VLANs."""
|
2017-08-26 13:10:18 +00:00
|
|
|
vlan = VlanForm(request.POST or None, instance=vlan_instance)
|
|
|
|
if vlan.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if vlan.changed_data:
|
|
|
|
vlan.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The VLAN was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-vlan"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"vlanform": vlan, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(Vlan)
|
|
|
|
def del_vlan(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete VLANs."""
|
2017-12-13 17:31:13 +00:00
|
|
|
vlan = DelVlanForm(request.POST or None, instances=instances)
|
2017-08-26 13:10:18 +00:00
|
|
|
if vlan.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
vlan_dels = vlan.cleaned_data["vlan"]
|
2017-09-10 22:33:45 +00:00
|
|
|
for vlan_del in vlan_dels:
|
2017-08-26 13:10:18 +00:00
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
vlan_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The VLAN was deleted."))
|
2017-08-26 13:10:18 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
2019-11-04 16:55:03 +00:00
|
|
|
request, (_("Error: the VLAN %s can't be deleted.") % vlan_del)
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-vlan"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"vlanform": vlan, "action_name": _("Delete")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
|
2017-09-10 22:33:45 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(Nas)
|
2017-09-10 22:33:45 +00:00
|
|
|
def add_nas(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create NAS devices."""
|
2017-09-10 22:33:45 +00:00
|
|
|
nas = NasForm(request.POST or None)
|
|
|
|
if nas.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
nas.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The NAS device was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-nas"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"nasform": nas, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-09-10 22:33:45 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Nas)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_nas(request, nas_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit NAS devices."""
|
2017-09-10 22:33:45 +00:00
|
|
|
nas = NasForm(request.POST or None, instance=nas_instance)
|
|
|
|
if nas.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if nas.changed_data:
|
|
|
|
nas.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The NAS device was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-nas"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"nasform": nas, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-09-10 22:33:45 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-13 17:31:13 +00:00
|
|
|
@can_delete_set(Nas)
|
|
|
|
def del_nas(request, instances):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete NAS devices."""
|
2017-12-13 17:31:13 +00:00
|
|
|
nas = DelNasForm(request.POST or None, instances=instances)
|
2017-09-10 22:33:45 +00:00
|
|
|
if nas.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
nas_dels = nas.cleaned_data["nas"]
|
2017-09-10 22:33:45 +00:00
|
|
|
for nas_del in nas_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
nas_del.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The NAS device was deleted."))
|
2017-09-10 22:33:45 +00:00
|
|
|
except ProtectedError:
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
2019-11-04 16:55:03 +00:00
|
|
|
request, (_("Error: the NAS device %s can't be deleted.") % nas_del)
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-nas"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"nasform": nas, "action_name": _("Delete")}, "machines/machine.html", request
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-09-10 22:33:45 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_view_all(Machine)
|
2016-07-04 00:48:24 +00:00
|
|
|
def index(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""The home view for this app. Displays the list of registered
|
|
|
|
machines in Re2o."""
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_large_number = GeneralOption.get_cached_value("pagination_large_number")
|
|
|
|
machines_list = (
|
|
|
|
Machine.objects.select_related("user")
|
|
|
|
.prefetch_related("interface_set__domain__extension")
|
|
|
|
.prefetch_related("interface_set__ipv4__ip_type")
|
|
|
|
.prefetch_related("interface_set__machine_type__ip_type__extension")
|
|
|
|
.prefetch_related("interface_set__domain__related_domain__extension")
|
|
|
|
.prefetch_related("interface_set__ipv6list")
|
2017-10-22 00:33:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
machines_list = SortTable.sort(
|
2018-04-13 22:48:44 +00:00
|
|
|
machines_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.MACHINES_INDEX,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
machines_list = re2o_paginator(request, machines_list, pagination_large_number)
|
|
|
|
return render(request, "machines/index.html", {"machines_list": machines_list})
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2016-07-08 00:48:44 +00:00
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_view_all(IpType)
|
2016-10-22 22:55:58 +00:00
|
|
|
def index_iptype(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to display the list of existing types of IP."""
|
2019-11-04 16:55:03 +00:00
|
|
|
iptype_list = (
|
|
|
|
IpType.objects.select_related("extension")
|
|
|
|
.select_related("vlan")
|
|
|
|
.order_by("name")
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "machines/index_iptype.html", {"iptype_list": iptype_list})
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2016-10-22 22:55:58 +00:00
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_view_all(Vlan)
|
2017-08-26 13:10:18 +00:00
|
|
|
def index_vlan(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to display the list of existing VLANs."""
|
2019-11-04 16:55:03 +00:00
|
|
|
vlan_list = Vlan.objects.prefetch_related("iptype_set").order_by("vlan_id")
|
|
|
|
return render(request, "machines/index_vlan.html", {"vlan_list": vlan_list})
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_view_all(MachineType)
|
2016-07-08 00:48:44 +00:00
|
|
|
def index_machinetype(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to display the list of existing types of machines."""
|
2019-11-04 16:55:03 +00:00
|
|
|
machinetype_list = MachineType.objects.select_related("ip_type").order_by("name")
|
2018-04-13 22:48:44 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/index_machinetype.html",
|
|
|
|
{"machinetype_list": machinetype_list},
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
|
2017-09-10 22:33:45 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_view_all(Nas)
|
2017-09-10 22:33:45 +00:00
|
|
|
def index_nas(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to display the list of existing NAS devices."""
|
2019-11-04 16:55:03 +00:00
|
|
|
nas_list = (
|
|
|
|
Nas.objects.select_related("machine_type")
|
|
|
|
.select_related("nas_type")
|
|
|
|
.order_by("name")
|
|
|
|
)
|
|
|
|
return render(request, "machines/index_nas.html", {"nas_list": nas_list})
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2017-09-10 22:33:45 +00:00
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
@login_required
|
2018-06-25 14:50:45 +00:00
|
|
|
@can_view_all(SOA, Mx, Ns, Txt, DName, Srv, Extension)
|
2016-07-08 15:54:06 +00:00
|
|
|
def index_extension(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to display the list of existing extensions, the list of
|
2018-04-14 18:19:02 +00:00
|
|
|
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
|
2020-04-29 22:17:01 +00:00
|
|
|
existing SRV records.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
extension_list = (
|
|
|
|
Extension.objects.select_related("origin")
|
|
|
|
.select_related("soa")
|
|
|
|
.order_by("name")
|
|
|
|
)
|
|
|
|
soa_list = SOA.objects.order_by("name")
|
|
|
|
mx_list = (
|
|
|
|
Mx.objects.order_by("zone")
|
|
|
|
.select_related("zone")
|
|
|
|
.select_related("name__extension")
|
|
|
|
)
|
|
|
|
ns_list = (
|
|
|
|
Ns.objects.order_by("zone")
|
|
|
|
.select_related("zone")
|
|
|
|
.select_related("ns__extension")
|
|
|
|
)
|
|
|
|
txt_list = Txt.objects.all().select_related("zone")
|
|
|
|
dname_list = DName.objects.all().select_related("zone")
|
|
|
|
srv_list = (
|
|
|
|
Srv.objects.all()
|
|
|
|
.select_related("extension")
|
|
|
|
.select_related("target__extension")
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/index_extension.html",
|
2018-04-13 22:48:44 +00:00
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"extension_list": extension_list,
|
|
|
|
"soa_list": soa_list,
|
|
|
|
"mx_list": mx_list,
|
|
|
|
"ns_list": ns_list,
|
|
|
|
"txt_list": txt_list,
|
|
|
|
"dname_list": dname_list,
|
|
|
|
"srv_list": srv_list,
|
|
|
|
},
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-07-18 21:22:59 +00:00
|
|
|
|
2016-11-19 20:15:43 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_edit(Interface)
|
|
|
|
def index_alias(request, interface, interfaceid):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to display the list of existing aliases of an interface."""
|
2018-04-13 22:48:44 +00:00
|
|
|
alias_list = Domain.objects.filter(
|
|
|
|
cname=Domain.objects.filter(interface_parent=interface)
|
2019-11-04 16:55:03 +00:00
|
|
|
).order_by("name")
|
2018-04-13 22:48:44 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/index_alias.html",
|
|
|
|
{"alias_list": alias_list, "interface_id": interfaceid},
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2016-11-19 20:15:43 +00:00
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
@login_required
|
2018-07-29 11:40:49 +00:00
|
|
|
@can_view(Machine)
|
2018-07-29 17:07:40 +00:00
|
|
|
def index_sshfp(request, machine, machineid):
|
|
|
|
"""View used to display the list of existing SSHFP records associated
|
2020-04-29 22:17:01 +00:00
|
|
|
with a machine."""
|
2018-07-29 17:07:40 +00:00
|
|
|
sshfp_list = SshFp.objects.filter(machine=machine)
|
2018-06-23 15:59:34 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/index_sshfp.html",
|
|
|
|
{"sshfp_list": sshfp_list, "machine_id": machineid},
|
2018-06-23 15:59:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2018-08-06 22:01:46 +00:00
|
|
|
@can_view(Interface)
|
2018-01-29 02:53:49 +00:00
|
|
|
def index_ipv6(request, interface, interfaceid):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to display the list of existing IPv6 of an interface."""
|
2018-01-29 02:53:49 +00:00
|
|
|
ipv6_list = Ipv6List.objects.filter(interface=interface)
|
2018-04-13 22:48:44 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/index_ipv6.html",
|
|
|
|
{"ipv6_list": ipv6_list, "interface_id": interfaceid},
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
|
2018-06-23 14:39:03 +00:00
|
|
|
@login_required
|
|
|
|
@can_view_all(Role)
|
|
|
|
def index_role(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to display the list of existing roles."""
|
2019-11-04 16:55:03 +00:00
|
|
|
role_list = Role.objects.prefetch_related("servers__domain__extension").all()
|
|
|
|
return render(request, "machines/index_role.html", {"role_list": role_list})
|
2018-06-23 14:39:03 +00:00
|
|
|
|
|
|
|
|
2017-08-08 04:56:19 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_view_all(Service)
|
2017-08-08 04:56:19 +00:00
|
|
|
def index_service(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to display the list of existing services."""
|
2019-11-04 16:55:03 +00:00
|
|
|
service_list = Service.objects.prefetch_related(
|
|
|
|
"service_link_set__server__domain__extension"
|
|
|
|
).all()
|
|
|
|
servers_list = (
|
|
|
|
Service_link.objects.select_related("server__domain__extension")
|
|
|
|
.select_related("service")
|
|
|
|
.all()
|
|
|
|
)
|
2018-04-13 22:48:44 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/index_service.html",
|
|
|
|
{"service_list": service_list, "servers_list": servers_list},
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2017-08-08 04:56:19 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
|
2017-09-29 20:28:48 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_view_all(OuverturePortList)
|
2017-09-29 20:28:48 +00:00
|
|
|
def index_portlist(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to display the list of existing port policies."""
|
2019-11-04 16:55:03 +00:00
|
|
|
port_list = (
|
|
|
|
OuverturePortList.objects.prefetch_related("ouvertureport_set")
|
|
|
|
.prefetch_related("interface_set__domain__extension")
|
|
|
|
.prefetch_related("interface_set__machine__user")
|
|
|
|
.order_by("name")
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "machines/index_portlist.html", {"port_list": port_list})
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2017-09-29 20:28:48 +00:00
|
|
|
|
2017-09-30 08:04:18 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(OuverturePortList)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_portlist(request, ouvertureportlist_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to edit port policies."""
|
2018-04-13 22:48:44 +00:00
|
|
|
port_list = EditOuverturePortListForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=ouvertureportlist_instance
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2017-10-01 19:57:10 +00:00
|
|
|
port_formset = modelformset_factory(
|
2018-04-13 22:48:44 +00:00
|
|
|
OuverturePort,
|
2019-11-04 16:55:03 +00:00
|
|
|
fields=("begin", "end", "protocole", "io"),
|
2018-04-13 22:48:44 +00:00
|
|
|
extra=0,
|
|
|
|
can_delete=True,
|
|
|
|
min_num=1,
|
|
|
|
validate_min=True,
|
2019-11-04 16:55:03 +00:00
|
|
|
)(request.POST or None, queryset=ouvertureportlist_instance.ouvertureport_set.all())
|
2017-10-01 19:57:10 +00:00
|
|
|
if port_list.is_valid() and port_formset.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if port_list.changed_data:
|
|
|
|
pl = port_list.save()
|
|
|
|
else:
|
|
|
|
pl = ouvertureportlist_instance
|
2017-10-01 19:57:10 +00:00
|
|
|
instances = port_formset.save(commit=False)
|
|
|
|
for to_delete in port_formset.deleted_objects:
|
|
|
|
to_delete.delete()
|
|
|
|
for port in instances:
|
|
|
|
port.port_list = pl
|
|
|
|
port.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The ports list was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-portlist"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"port_list": port_list, "ports": port_formset},
|
|
|
|
"machines/edit_portlist.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-09-30 08:04:18 +00:00
|
|
|
|
2017-10-01 15:09:00 +00:00
|
|
|
@login_required
|
2017-12-09 01:15:11 +00:00
|
|
|
@can_delete(OuverturePortList)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_portlist(request, port_list_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to delete port policies."""
|
2017-10-01 15:09:00 +00:00
|
|
|
port_list_instance.delete()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The ports list was deleted."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-portlist"))
|
2017-10-01 15:09:00 +00:00
|
|
|
|
2018-04-13 22:48:44 +00:00
|
|
|
|
2017-10-01 15:19:42 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_create(OuverturePortList)
|
2017-10-01 15:19:42 +00:00
|
|
|
def add_portlist(request):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View used to create port policies."""
|
2017-10-02 02:19:07 +00:00
|
|
|
port_list = EditOuverturePortListForm(request.POST or None)
|
2017-10-01 20:04:37 +00:00
|
|
|
port_formset = modelformset_factory(
|
2018-07-17 19:26:42 +00:00
|
|
|
OuverturePort,
|
2019-11-04 16:55:03 +00:00
|
|
|
fields=("begin", "end", "protocole", "io"),
|
2018-07-17 19:26:42 +00:00
|
|
|
extra=0,
|
|
|
|
can_delete=True,
|
|
|
|
min_num=1,
|
|
|
|
validate_min=True,
|
2017-10-02 02:19:07 +00:00
|
|
|
)(request.POST or None, queryset=OuverturePort.objects.none())
|
2017-10-01 20:04:37 +00:00
|
|
|
if port_list.is_valid() and port_formset.is_valid():
|
|
|
|
pl = port_list.save()
|
|
|
|
instances = port_formset.save(commit=False)
|
|
|
|
for to_delete in port_formset.deleted_objects:
|
|
|
|
to_delete.delete()
|
|
|
|
for port in instances:
|
|
|
|
port.port_list = pl
|
|
|
|
port.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The ports list was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index-portlist"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"port_list": port_list, "ports": port_formset},
|
|
|
|
"machines/edit_portlist.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|
2017-10-01 15:09:00 +00:00
|
|
|
|
2017-10-01 22:08:07 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_create(OuverturePort)
|
|
|
|
@can_edit(Interface)
|
2018-04-15 01:00:05 +00:00
|
|
|
def configure_ports(request, interface_instance, **_kwargs):
|
2020-04-29 22:17:01 +00:00
|
|
|
"""View to display the list of configured port policies for an
|
|
|
|
interface.
|
|
|
|
"""
|
2017-10-02 02:54:40 +00:00
|
|
|
if not interface_instance.may_have_port_open():
|
2018-04-13 22:48:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
2019-11-16 14:07:15 +00:00
|
|
|
"Warning: the IP address is not public, the opening won't"
|
|
|
|
" have any effect in v4."
|
2019-11-04 16:55:03 +00:00
|
|
|
)
|
|
|
|
),
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
interface = EditOuverturePortConfigForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=interface_instance
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
2017-10-01 22:08:07 +00:00
|
|
|
if interface.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if interface.changed_data:
|
|
|
|
interface.save()
|
2018-08-05 16:48:22 +00:00
|
|
|
messages.success(request, _("The ports configuration was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("machines:index"))
|
2018-04-13 22:48:44 +00:00
|
|
|
return form(
|
2019-11-16 14:07:15 +00:00
|
|
|
{"interfaceform": interface, "action_name": _("Edit")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"machines/machine.html",
|
|
|
|
request,
|
2018-04-13 22:48:44 +00:00
|
|
|
)
|
|
|
|
|