2017-10-06 23:37:22 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2017-01-15 23:01:18 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
|
|
|
# Copyright © 2017 Gabriel Détraz
|
|
|
|
# Copyright © 2017 Goulven Kermarec
|
|
|
|
# Copyright © 2017 Augustin Lemesle
|
2017-10-06 23:37:22 +00:00
|
|
|
# Copyright © 2017 Maël Kervella
|
2017-01-15 23:01:18 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
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
|
2017-09-10 23:29:24 +00:00
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-10-26 15:58:41 +00:00
|
|
|
from django.urls import reverse
|
2016-07-18 21:22:59 +00:00
|
|
|
from django.http import HttpResponse
|
2016-07-04 00:48:24 +00:00
|
|
|
from django.shortcuts import render, redirect
|
2016-12-12 12:32:18 +00:00
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
from django.template.context_processors import csrf
|
2016-07-22 01:25:04 +00:00
|
|
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
2016-07-04 00:48:24 +00:00
|
|
|
from django.template import Context, RequestContext, loader
|
|
|
|
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
|
2017-10-01 20:04:37 +00:00
|
|
|
from django.forms import ValidationError, modelformset_factory
|
2016-11-11 20:10:10 +00:00
|
|
|
from django.contrib.auth import authenticate, login
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
2016-07-02 22:27:22 +00:00
|
|
|
|
2016-07-18 21:22:59 +00:00
|
|
|
from rest_framework.renderers import JSONRenderer
|
2017-10-14 10:40:22 +00:00
|
|
|
from machines.serializers import ( FullInterfaceSerializer,
|
|
|
|
InterfaceSerializer,
|
|
|
|
TypeSerializer,
|
|
|
|
DomainSerializer,
|
2017-11-15 14:17:22 +00:00
|
|
|
TxtSerializer,
|
2017-11-16 01:33:57 +00:00
|
|
|
SrvSerializer,
|
2017-10-14 10:40:22 +00:00
|
|
|
MxSerializer,
|
|
|
|
ExtensionSerializer,
|
|
|
|
ServiceServersSerializer,
|
|
|
|
NsSerializer,
|
|
|
|
OuverturePortsSerializer
|
|
|
|
)
|
2016-07-21 14:58:12 +00:00
|
|
|
from reversion import revisions as reversion
|
2016-12-11 16:24:04 +00:00
|
|
|
from reversion.models import Version
|
2016-07-18 21:22:59 +00:00
|
|
|
|
2016-07-10 22:52:36 +00:00
|
|
|
import re
|
2017-10-14 10:40:22 +00:00
|
|
|
from .forms import (
|
|
|
|
NewMachineForm,
|
|
|
|
EditMachineForm,
|
|
|
|
EditInterfaceForm,
|
|
|
|
AddInterfaceForm,
|
|
|
|
MachineTypeForm,
|
|
|
|
DelMachineTypeForm,
|
|
|
|
ExtensionForm,
|
|
|
|
DelExtensionForm,
|
|
|
|
)
|
|
|
|
from .forms import (
|
|
|
|
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,
|
2017-10-14 10:40:22 +00:00
|
|
|
MxForm,
|
|
|
|
DelMxForm,
|
|
|
|
VlanForm,
|
|
|
|
DelVlanForm,
|
|
|
|
ServiceForm,
|
|
|
|
DelServiceForm,
|
|
|
|
NasForm,
|
2017-11-16 01:33:57 +00:00
|
|
|
DelNasForm,
|
|
|
|
SrvForm,
|
|
|
|
DelSrvForm,
|
2018-01-29 02:53:49 +00:00
|
|
|
Ipv6ListForm,
|
2017-10-14 10:40:22 +00:00
|
|
|
)
|
2017-10-02 02:19:07 +00:00
|
|
|
from .forms import EditOuverturePortListForm, EditOuverturePortConfigForm
|
2017-10-14 10:40:22 +00:00
|
|
|
from .models import (
|
|
|
|
IpType,
|
|
|
|
Machine,
|
|
|
|
Interface,
|
|
|
|
IpList,
|
|
|
|
MachineType,
|
|
|
|
Extension,
|
2017-10-19 23:52:38 +00:00
|
|
|
SOA,
|
2017-10-14 10:40:22 +00:00
|
|
|
Mx,
|
|
|
|
Ns,
|
|
|
|
Domain,
|
|
|
|
Service,
|
|
|
|
Service_link,
|
|
|
|
Vlan,
|
|
|
|
Nas,
|
2017-11-15 14:17:22 +00:00
|
|
|
Txt,
|
2017-11-16 01:33:57 +00:00
|
|
|
Srv,
|
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
|
|
|
)
|
2016-07-04 00:48:24 +00:00
|
|
|
from users.models import User
|
2017-06-25 23:29:34 +00:00
|
|
|
from preferences.models import GeneralOption, OptionalMachine
|
2017-10-15 16:35:35 +00:00
|
|
|
from re2o.utils import (
|
|
|
|
all_active_assigned_interfaces,
|
|
|
|
all_has_access,
|
2017-10-22 00:33:44 +00:00
|
|
|
filter_active_interfaces,
|
2017-11-30 20:38:16 +00:00
|
|
|
SortTable,
|
2017-12-29 00:51:24 +00:00
|
|
|
)
|
|
|
|
from re2o.acl import (
|
2017-11-30 20:38:16 +00:00
|
|
|
can_create,
|
2017-12-09 01:15:11 +00:00
|
|
|
can_edit,
|
|
|
|
can_delete,
|
2017-12-13 17:31:13 +00:00
|
|
|
can_view,
|
2017-12-27 00:59:48 +00:00
|
|
|
can_view_all,
|
2017-12-13 17:31:13 +00:00
|
|
|
can_delete_set,
|
2017-10-15 16:35:35 +00:00
|
|
|
)
|
2017-10-15 01:47:17 +00:00
|
|
|
from re2o.views import form
|
2016-07-04 00:48:24 +00:00
|
|
|
|
2017-10-07 17:00:55 +00:00
|
|
|
def f_type_id( is_type_tt ):
|
|
|
|
""" 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
|
|
|
|
"""
|
2017-10-08 23:34:49 +00:00
|
|
|
return 'id_Interface-type_hidden' if is_type_tt else 'id_Interface-type'
|
2017-10-06 23:16:19 +00:00
|
|
|
|
2017-10-07 17:00:55 +00:00
|
|
|
def generate_ipv4_choices( form ) :
|
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
|
|
|
"""
|
|
|
|
f_ipv4 = form.fields['ipv4']
|
|
|
|
used_mtype_id = []
|
2017-10-08 00:48:32 +00:00
|
|
|
choices = '{"":[{key:"",value:"Choisissez d\'abord un type de machine"},'
|
2017-10-07 17:00:55 +00:00
|
|
|
mtype_id = -1
|
|
|
|
|
2017-10-14 10:40:22 +00:00
|
|
|
for ip in f_ipv4.queryset.annotate(mtype_id=F('ip_type__machinetype__id'))\
|
|
|
|
.order_by('mtype_id', 'id') :
|
2017-10-07 17:00:55 +00:00
|
|
|
if mtype_id != ip.mtype_id :
|
|
|
|
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(
|
|
|
|
t = mtype_id,
|
|
|
|
v = f_ipv4.empty_label or '""'
|
|
|
|
)
|
|
|
|
choices += '{{key:{k},value:"{v}"}},'.format(
|
|
|
|
k = ip.id,
|
|
|
|
v = ip.ipv4
|
|
|
|
)
|
2017-10-07 17:00:55 +00:00
|
|
|
|
|
|
|
for t in form.fields['type'].queryset.exclude(id__in=used_mtype_id) :
|
|
|
|
choices += '], "'+str(t.id)+'": ['
|
|
|
|
choices += '{key: "", value: "' + str(f_ipv4.empty_label) + '"},'
|
|
|
|
choices += ']}'
|
|
|
|
return choices
|
|
|
|
|
|
|
|
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 (
|
|
|
|
'new Bloodhound( {{'
|
|
|
|
'datumTokenizer: Bloodhound.tokenizers.obj.whitespace( "value" ),'
|
|
|
|
'queryTokenizer: Bloodhound.tokenizers.whitespace,'
|
|
|
|
'local: choices_ipv4[ $( "#{type_id}" ).val() ],'
|
|
|
|
'identify: function( obj ) {{ return obj.key; }}'
|
|
|
|
'}} )'
|
|
|
|
).format(
|
|
|
|
type_id = f_type_id( is_type_tt )
|
|
|
|
)
|
2017-10-07 17:00:55 +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 (
|
|
|
|
'function(q, sync) {{'
|
|
|
|
'if (q === "") {{'
|
|
|
|
'var first = choices_ipv4[$("#{type_id}").val()].slice(0, 5);'
|
|
|
|
'first = first.map( function (obj) {{ return obj.key; }} );'
|
|
|
|
'sync(engine_ipv4.get(first));'
|
|
|
|
'}} else {{'
|
|
|
|
'engine_ipv4.search(q, sync);'
|
|
|
|
'}}'
|
|
|
|
'}}'
|
|
|
|
).format(
|
|
|
|
type_id = f_type_id( is_type_tt )
|
|
|
|
)
|
2017-10-06 23:16:19 +00:00
|
|
|
|
2017-10-14 13:27:56 +00:00
|
|
|
def generate_ipv4_mbf_param( form, is_type_tt ):
|
|
|
|
""" Generate all the parameters to use with the massive_bootstrap_form
|
2017-10-07 17:00:55 +00:00
|
|
|
tag """
|
|
|
|
i_choices = { 'ipv4': generate_ipv4_choices( form ) }
|
|
|
|
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 )] }
|
2017-10-15 18:47:14 +00:00
|
|
|
i_gen_select = { 'ipv4': False }
|
2017-10-14 13:27:56 +00:00
|
|
|
i_mbf_param = {
|
2017-10-07 17:00:55 +00:00
|
|
|
'choices': i_choices,
|
|
|
|
'engine': i_engine,
|
|
|
|
'match_func': i_match_func,
|
2017-10-15 18:47:14 +00:00
|
|
|
'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
|
|
|
|
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)
|
|
|
|
def new_machine(request, user, userid):
|
2017-12-29 00:51:24 +00:00
|
|
|
""" Fonction de creation d'une machine. Cree l'objet machine,
|
2017-10-14 10:40:22 +00:00
|
|
|
le sous objet interface et l'objet domain à partir de model forms.
|
2017-10-07 22:21:46 +00:00
|
|
|
Trop complexe, devrait être simplifié"""
|
2017-11-28 22:33:47 +00:00
|
|
|
|
2018-01-08 22:57:19 +00:00
|
|
|
machine = NewMachineForm(request.POST or None, user=request.user)
|
2017-11-28 22:33:47 +00:00
|
|
|
interface = AddInterfaceForm(
|
|
|
|
request.POST or None,
|
2017-12-30 00:48:23 +00:00
|
|
|
user=request.user
|
2017-11-28 22:33:47 +00:00
|
|
|
)
|
2017-10-18 00:27:42 +00:00
|
|
|
domain = DomainForm(request.POST or None, user=user)
|
2017-08-01 04:57:56 +00:00
|
|
|
if machine.is_valid() and interface.is_valid():
|
|
|
|
new_machine = machine.save(commit=False)
|
|
|
|
new_machine.user = user
|
|
|
|
new_interface = interface.save(commit=False)
|
|
|
|
domain.instance.interface_parent = new_interface
|
|
|
|
if domain.is_valid():
|
2017-01-13 21:25:03 +00:00
|
|
|
new_domain = domain.save(commit=False)
|
2018-03-31 15:18:39 +00:00
|
|
|
new_machine.save()
|
2017-07-21 03:06:53 +00:00
|
|
|
new_interface.machine = new_machine
|
2018-03-31 15:18:39 +00:00
|
|
|
new_interface.save()
|
2017-07-21 03:06:53 +00:00
|
|
|
new_domain.interface_parent = new_interface
|
2018-03-31 15:18:39 +00:00
|
|
|
new_domain.save()
|
2017-09-10 12:52:40 +00:00
|
|
|
messages.success(request, "La machine a été créée")
|
2017-10-26 15:58:41 +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(
|
|
|
|
{
|
|
|
|
'machineform': machine,
|
|
|
|
'interfaceform': interface,
|
|
|
|
'domainform': domain,
|
2018-01-31 05:25:39 +00:00
|
|
|
'i_mbf_param': i_mbf_param,
|
|
|
|
'action_name' : 'Créer une machine'
|
2017-11-28 22:33:47 +00:00
|
|
|
},
|
|
|
|
'machines/machine.html',
|
|
|
|
request
|
|
|
|
)
|
2016-07-04 00:48:24 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Interface)
|
|
|
|
def edit_interface(request, interface_instance, interfaceid):
|
2017-10-07 22:21:46 +00:00
|
|
|
""" Edition d'une interface. Distingue suivant les droits les valeurs de interfaces et machines que l'user peut modifier
|
|
|
|
infra permet de modifier le propriétaire"""
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2017-12-30 00:48:23 +00:00
|
|
|
machine_form = EditMachineForm(
|
|
|
|
request.POST or None,
|
|
|
|
instance=interface_instance.machine,
|
|
|
|
user=request.user
|
|
|
|
)
|
2018-01-08 22:57:19 +00:00
|
|
|
interface_form = EditInterfaceForm(request.POST or None, instance=interface_instance, user=request.user)
|
2017-11-30 20:38:16 +00:00
|
|
|
domain_form = DomainForm(request.POST or None, instance=interface_instance.domain)
|
2017-08-01 04:57:56 +00:00
|
|
|
if machine_form.is_valid() and interface_form.is_valid() and domain_form.is_valid():
|
|
|
|
new_machine = machine_form.save(commit=False)
|
|
|
|
new_interface = interface_form.save(commit=False)
|
|
|
|
new_domain = domain_form.save(commit=False)
|
2018-03-31 15:18:39 +00:00
|
|
|
new_machine.save()
|
|
|
|
new_interface.save()
|
|
|
|
new_domain.save()
|
2017-08-01 04:57:56 +00:00
|
|
|
messages.success(request, "La machine a été modifiée")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse(
|
|
|
|
'users:profil',
|
2017-11-30 20:38:16 +00:00
|
|
|
kwargs={'userid':str(interface_instance.machine.user.id)}
|
2017-10-26 15:58:41 +00:00
|
|
|
))
|
2017-10-14 13:27:56 +00:00
|
|
|
i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({
|
|
|
|
'machineform': machine_form,
|
|
|
|
'interfaceform': interface_form,
|
|
|
|
'domainform': domain_form,
|
|
|
|
'i_mbf_param': i_mbf_param,
|
|
|
|
'action_name' : 'Editer une interface'
|
|
|
|
}, 'machines/machine.html', request)
|
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)
|
|
|
|
def del_machine(request, machine, machineid):
|
2017-10-07 22:21:46 +00:00
|
|
|
""" Supprime une machine, interfaces en mode cascade"""
|
2016-07-18 16:37:52 +00:00
|
|
|
if request.method == "POST":
|
2018-03-31 15:18:39 +00:00
|
|
|
machine.delete()
|
2016-07-18 16:37:52 +00:00
|
|
|
messages.success(request, "La machine a été détruite")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse(
|
|
|
|
'users:profil',
|
|
|
|
kwargs={'userid':str(machine.user.id)}
|
|
|
|
))
|
2016-07-18 16:37:52 +00:00
|
|
|
return form({'objet': machine, 'objet_name': 'machine'}, 'machines/delete.html', request)
|
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)
|
|
|
|
def new_interface(request, machine, machineid):
|
2017-10-07 22:21:46 +00:00
|
|
|
""" Ajoute une interface et son domain associé à une machine existante"""
|
2017-11-29 00:53:32 +00:00
|
|
|
|
2018-01-08 22:57:19 +00:00
|
|
|
interface_form = AddInterfaceForm(request.POST or None, user=request.user)
|
2017-07-23 02:22:22 +00:00
|
|
|
domain_form = DomainForm(request.POST or None)
|
2017-08-01 04:57:56 +00:00
|
|
|
if interface_form.is_valid():
|
|
|
|
new_interface = interface_form.save(commit=False)
|
|
|
|
domain_form.instance.interface_parent = new_interface
|
|
|
|
new_interface.machine = machine
|
|
|
|
if domain_form.is_valid():
|
2017-01-14 11:52:23 +00:00
|
|
|
new_domain = domain_form.save(commit=False)
|
2018-03-31 15:18:39 +00:00
|
|
|
new_interface.save()
|
2017-07-21 03:06:53 +00:00
|
|
|
new_domain.interface_parent = new_interface
|
2018-03-31 15:18:39 +00:00
|
|
|
new_domain.save()
|
2017-07-21 03:06:53 +00:00
|
|
|
messages.success(request, "L'interface a été ajoutée")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse(
|
|
|
|
'users:profil',
|
|
|
|
kwargs={'userid':str(machine.user.id)}
|
|
|
|
))
|
2017-10-14 13:27:56 +00:00
|
|
|
i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({
|
|
|
|
'interfaceform': interface_form,
|
|
|
|
'domainform': domain_form,
|
|
|
|
'i_mbf_param': i_mbf_param,
|
|
|
|
'action_name' : 'Créer une interface'
|
|
|
|
}, 'machines/machine.html', request)
|
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)
|
|
|
|
def del_interface(request, interface, interfaceid):
|
2017-10-07 22:21:46 +00:00
|
|
|
""" Supprime une interface. Domain objet en mode 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()
|
2016-07-18 16:37:52 +00:00
|
|
|
messages.success(request, "L'interface a été détruite")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse(
|
|
|
|
'users:profil',
|
|
|
|
kwargs={'userid':str(request.user.id)}
|
|
|
|
))
|
2016-07-18 16:37:52 +00:00
|
|
|
return form({'objet': interface, 'objet_name': 'interface'}, 'machines/delete.html', request)
|
2016-07-18 03:30:35 +00:00
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(Ipv6List)
|
|
|
|
@can_edit(Interface)
|
|
|
|
def new_ipv6list(request, interface, interfaceid):
|
|
|
|
"""Nouvelle ipv6"""
|
2018-01-30 02:01:06 +00:00
|
|
|
ipv6list_instance = Ipv6List(interface=interface)
|
|
|
|
ipv6 = Ipv6ListForm(request.POST or None, instance=ipv6list_instance, user=request.user)
|
2018-01-29 02:53:49 +00:00
|
|
|
if ipv6.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
ipv6.save()
|
2018-01-29 02:53:49 +00:00
|
|
|
messages.success(request, "Ipv6 ajoutée")
|
|
|
|
return redirect(reverse(
|
|
|
|
'machines:index-ipv6',
|
|
|
|
kwargs={'interfaceid':str(interface.id)}
|
|
|
|
))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'ipv6form': ipv6, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2018-01-29 02:53:49 +00:00
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(Ipv6List)
|
|
|
|
def edit_ipv6list(request, ipv6list_instance, ipv6listid):
|
|
|
|
"""Edition d'une ipv6"""
|
|
|
|
ipv6 = Ipv6ListForm(request.POST or None, instance=ipv6list_instance, user=request.user)
|
|
|
|
if ipv6.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
ipv6.save()
|
2018-01-29 02:53:49 +00:00
|
|
|
messages.success(request, "Ipv6 modifiée")
|
|
|
|
return redirect(reverse(
|
|
|
|
'machines:index-ipv6',
|
|
|
|
kwargs={'interfaceid':str(ipv6list_instance.interface.id)}
|
|
|
|
))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'ipv6form': ipv6, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
2018-01-29 02:53:49 +00:00
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(Ipv6List)
|
|
|
|
def del_ipv6list(request, ipv6list, ipv6listid):
|
|
|
|
""" Supprime une ipv6"""
|
|
|
|
if request.method == "POST":
|
|
|
|
interfaceid = ipv6list.interface.id
|
2018-03-31 15:18:39 +00:00
|
|
|
ipv6list.delete()
|
2018-01-29 02:53:49 +00:00
|
|
|
messages.success(request, "L'ipv6 a été détruite")
|
|
|
|
return redirect(reverse(
|
|
|
|
'machines:index-ipv6',
|
|
|
|
kwargs={'interfaceid':str(interfaceid)}
|
|
|
|
))
|
|
|
|
return form({'objet': ipv6list, 'objet_name': 'ipv6'}, 'machines/delete.html', request)
|
|
|
|
|
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):
|
2017-10-07 22:21:46 +00:00
|
|
|
""" Ajoute un range d'ip. Intelligence dans le models, fonction views minimaliste"""
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2016-10-22 22:55:58 +00:00
|
|
|
messages.success(request, "Ce type d'ip a été ajouté")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-iptype'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'iptypeform': iptype, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2016-10-22 22:55:58 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(IpType)
|
|
|
|
def edit_iptype(request, iptype_instance, iptypeid):
|
2017-10-07 22:21:46 +00:00
|
|
|
""" Edition d'un range. Ne permet pas de le redimensionner pour éviter l'incohérence"""
|
2017-11-29 23:45:53 +00:00
|
|
|
|
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 15:18:39 +00:00
|
|
|
iptype.save()
|
2016-10-22 22:55:58 +00:00
|
|
|
messages.success(request, "Type d'ip modifié")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-iptype'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'iptypeform': iptype, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
2017-10-07 22:21:46 +00:00
|
|
|
""" Suppression d'un range ip. Supprime les objets ip associés"""
|
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():
|
|
|
|
iptype_dels = iptype.cleaned_data['iptypes']
|
|
|
|
for iptype_del in iptype_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
iptype_del.delete()
|
2016-10-22 22:55:58 +00:00
|
|
|
messages.success(request, "Le type d'ip a été supprimé")
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "Le type d'ip %s est affectée à au moins une machine, vous ne pouvez pas le supprimer" % iptype_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-iptype'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'iptypeform': iptype, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2016-07-07 11:19:03 +00:00
|
|
|
messages.success(request, "Ce type de machine a été ajouté")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-machinetype'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'machinetypeform': machinetype, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
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)
|
|
|
|
def edit_machinetype(request, machinetype_instance, machinetypeid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2016-07-08 00:48:44 +00:00
|
|
|
machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance)
|
|
|
|
if machinetype.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
machinetype.save()
|
2016-07-08 00:48:44 +00:00
|
|
|
messages.success(request, "Type de machine modifié")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-machinetype'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'machinetypeform': machinetype, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
|
|
|
machinetype = DelMachineTypeForm(request.POST or None, instances=instances)
|
2016-07-07 11:19:03 +00:00
|
|
|
if machinetype.is_valid():
|
|
|
|
machinetype_dels = machinetype.cleaned_data['machinetypes']
|
|
|
|
for machinetype_del in machinetype_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
machinetype_del.delete()
|
2016-07-07 11:19:03 +00:00
|
|
|
messages.success(request, "Le type de machine a été supprimé")
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "Le type de machine %s est affectée à au moins une machine, vous ne pouvez pas le supprimer" % machinetype_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-machinetype'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'machinetypeform': machinetype, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2016-07-08 15:54:06 +00:00
|
|
|
messages.success(request, "Cette extension a été ajoutée")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'extensionform': extension, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2016-07-08 15:54:06 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Extension)
|
|
|
|
def edit_extension(request, extension_instance, extensionid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
extension = ExtensionForm(request.POST or None, instance=extension_instance)
|
|
|
|
if extension.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
extension.save()
|
2018-01-30 06:17:47 +00:00
|
|
|
messages.success(request, "Extension modifiée")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'extensionform': extension, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
|
|
|
extension = DelExtensionForm(request.POST or None, instances=instances)
|
2016-07-08 15:54:06 +00:00
|
|
|
if extension.is_valid():
|
|
|
|
extension_dels = extension.cleaned_data['extensions']
|
|
|
|
for extension_del in extension_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
extension_del.delete()
|
2016-07-08 15:54:06 +00:00
|
|
|
messages.success(request, "L'extension a été supprimée")
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "L'extension %s est affectée à au moins un type de machine, vous ne pouvez pas la supprimer" % extension_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'extensionform': extension, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2017-10-19 23:52:38 +00:00
|
|
|
messages.success(request, "Cet enregistrement SOA a été ajouté")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'soaform': soa, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2017-10-19 23:52:38 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(SOA)
|
|
|
|
def edit_soa(request, soa_instance, soaid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2017-10-19 23:52:38 +00:00
|
|
|
soa = SOAForm(request.POST or None, instance=soa_instance)
|
|
|
|
if soa.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
soa.save()
|
2017-10-19 23:52:38 +00:00
|
|
|
messages.success(request, "SOA modifié")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'soaform': soa, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
|
|
|
soa = DelSOAForm(request.POST or None, instances=instances)
|
2017-10-19 23:52:38 +00:00
|
|
|
if soa.is_valid():
|
|
|
|
soa_dels = soa.cleaned_data['soa']
|
|
|
|
for soa_del in soa_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
soa_del.delete()
|
2017-10-19 23:52:38 +00:00
|
|
|
messages.success(request, "Le SOA a été supprimée")
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "Erreur le SOA suivant %s ne peut être supprimé" % soa_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'soaform': soa, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2016-11-19 16:44:43 +00:00
|
|
|
messages.success(request, "Cet enregistrement mx a été ajouté")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'mxform': mx, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2016-11-19 16:44:43 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Mx)
|
|
|
|
def edit_mx(request, mx_instance, mxid):
|
2017-12-29 00:51:24 +00:00
|
|
|
|
2016-11-19 16:44:43 +00:00
|
|
|
mx = MxForm(request.POST or None, instance=mx_instance)
|
|
|
|
if mx.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
mx.save()
|
2016-11-19 16:44:43 +00:00
|
|
|
messages.success(request, "Mx modifié")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'mxform': mx, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
|
|
|
mx = DelMxForm(request.POST or None, instances=instances)
|
2016-11-19 16:44:43 +00:00
|
|
|
if mx.is_valid():
|
|
|
|
mx_dels = mx.cleaned_data['mx']
|
|
|
|
for mx_del in mx_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
mx_del.delete()
|
2016-11-19 16:44:43 +00:00
|
|
|
messages.success(request, "L'mx a été supprimée")
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "Erreur le Mx suivant %s ne peut être supprimé" % mx_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'mxform': mx, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2016-11-19 17:21:05 +00:00
|
|
|
messages.success(request, "Cet enregistrement ns a été ajouté")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'nsform': ns, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2016-11-19 17:21:05 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Ns)
|
|
|
|
def edit_ns(request, ns_instance, nsid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2016-11-19 17:21:05 +00:00
|
|
|
ns = NsForm(request.POST or None, instance=ns_instance)
|
|
|
|
if ns.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
ns.save()
|
2016-11-19 17:21:05 +00:00
|
|
|
messages.success(request, "Ns modifié")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'nsform': ns, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
|
|
|
ns = DelNsForm(request.POST or None, instances=instances)
|
2016-11-19 17:21:05 +00:00
|
|
|
if ns.is_valid():
|
|
|
|
ns_dels = ns.cleaned_data['ns']
|
|
|
|
for ns_del in ns_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
ns_del.delete()
|
2016-11-19 17:21:05 +00:00
|
|
|
messages.success(request, "Le ns a été supprimée")
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "Erreur le Ns suivant %s ne peut être supprimé" % ns_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'nsform': ns, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2017-09-05 16:18:41 +00:00
|
|
|
messages.success(request, "Cet enregistrement text a été ajouté")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'txtform': txt, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2017-09-05 16:18:41 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Txt)
|
|
|
|
def edit_txt(request, txt_instance, txtid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2017-10-11 21:33:21 +00:00
|
|
|
txt = TxtForm(request.POST or None, instance=txt_instance)
|
|
|
|
if txt.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
txt.save()
|
2017-10-11 21:33:21 +00:00
|
|
|
messages.success(request, "Txt modifié")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'txtform': txt, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
|
|
|
txt = DelTxtForm(request.POST or None, instances=instances)
|
2017-10-11 21:33:21 +00:00
|
|
|
if txt.is_valid():
|
|
|
|
txt_dels = txt.cleaned_data['txt']
|
|
|
|
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()
|
2017-10-11 21:33:21 +00:00
|
|
|
messages.success(request, "Le txt a été supprimé")
|
2017-09-05 16:18:41 +00:00
|
|
|
except ProtectedError:
|
2017-10-11 21:33:21 +00:00
|
|
|
messages.error(request, "Erreur le Txt suivant %s ne peut être supprimé" % txt_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'txtform': txt, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2017-11-16 01:33:57 +00:00
|
|
|
messages.success(request, "Cet enregistrement srv a été ajouté")
|
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'srvform': srv, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2017-11-16 01:33:57 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Srv)
|
|
|
|
def edit_srv(request, srv_instance, srvid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2017-11-16 01:33:57 +00:00
|
|
|
srv = SrvForm(request.POST or None, instance=srv_instance)
|
|
|
|
if srv.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
srv.save()
|
2017-11-16 01:33:57 +00:00
|
|
|
messages.success(request, "Srv modifié")
|
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'srvform': srv, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
|
|
|
srv = DelSrvForm(request.POST or None, instances=instances)
|
2017-11-16 01:33:57 +00:00
|
|
|
if srv.is_valid():
|
|
|
|
srv_dels = srv.cleaned_data['srv']
|
|
|
|
for srv_del in srv_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
srv_del.delete()
|
2017-11-16 01:33:57 +00:00
|
|
|
messages.success(request, "L'srv a été supprimée")
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "Erreur le Srv suivant %s ne peut être supprimé" % srv_del)
|
|
|
|
return redirect(reverse('machines:index-extension'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'srvform': srv, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2016-11-19 20:15:43 +00:00
|
|
|
messages.success(request, "Cet alias a été ajouté")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse(
|
2017-12-29 00:51:24 +00:00
|
|
|
'machines:index-alias',
|
2017-10-26 15:58:41 +00:00
|
|
|
kwargs={'interfaceid':str(interfaceid)}
|
|
|
|
))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'aliasform': alias, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2016-11-19 20:15:43 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Domain)
|
|
|
|
def edit_alias(request, domain_instance, domainid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2017-12-29 00:42:00 +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 15:18:39 +00:00
|
|
|
domain_instance = alias.save()
|
2016-11-19 20:15:43 +00:00
|
|
|
messages.success(request, "Alias modifié")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse(
|
2017-12-29 00:51:24 +00:00
|
|
|
'machines:index-alias',
|
2017-11-30 20:38:16 +00:00
|
|
|
kwargs={'interfaceid':str(domain_instance.cname.interface_parent.id)}
|
2017-10-26 15:58:41 +00:00
|
|
|
))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'aliasform': alias, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
2016-11-19 20:15:43 +00:00
|
|
|
alias = DelAliasForm(request.POST or None, interface=interface)
|
|
|
|
if alias.is_valid():
|
|
|
|
alias_dels = alias.cleaned_data['alias']
|
|
|
|
for alias_del in alias_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
alias_del.delete()
|
2016-11-19 20:15:43 +00:00
|
|
|
messages.success(request, "L'alias %s a été supprimé" % alias_del)
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "Erreur l'alias suivant %s ne peut être supprimé" % alias_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse(
|
2017-12-29 00:51:24 +00:00
|
|
|
'machines:index-alias',
|
2017-10-26 15:58:41 +00:00
|
|
|
kwargs={'interfaceid':str(interfaceid)}
|
|
|
|
))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'aliasform': alias, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
2016-11-19 20:15:43 +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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2017-08-08 04:56:19 +00:00
|
|
|
messages.success(request, "Cet enregistrement service a été ajouté")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-service'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'serviceform': service, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2017-08-08 04:56:19 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Service)
|
|
|
|
def edit_service(request, service_instance, serviceid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2017-08-08 04:56:19 +00:00
|
|
|
service = ServiceForm(request.POST or None, instance=service_instance)
|
|
|
|
if service.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
service.save()
|
2017-08-08 04:56:19 +00:00
|
|
|
messages.success(request, "Service modifié")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-service'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'serviceform': service, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
|
|
|
service = DelServiceForm(request.POST or None, instances=instances)
|
2017-08-08 04:56:19 +00:00
|
|
|
if service.is_valid():
|
|
|
|
service_dels = service.cleaned_data['service']
|
|
|
|
for service_del in service_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
service_del.delete()
|
2017-08-08 04:56:19 +00:00
|
|
|
messages.success(request, "Le service a été supprimée")
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "Erreur le service suivant %s ne peut être supprimé" % service_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-service'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'serviceform': service, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
2017-08-08 04:56:19 +00:00
|
|
|
|
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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2017-08-26 13:10:18 +00:00
|
|
|
messages.success(request, "Cet enregistrement vlan a été ajouté")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-vlan'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'vlanform': vlan, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2017-08-26 13:10:18 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Vlan)
|
|
|
|
def edit_vlan(request, vlan_instance, vlanid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
vlan = VlanForm(request.POST or None, instance=vlan_instance)
|
|
|
|
if vlan.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
vlan.save()
|
2017-08-26 13:10:18 +00:00
|
|
|
messages.success(request, "Vlan modifié")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-vlan'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'vlanform': vlan, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
|
|
|
vlan = DelVlanForm(request.POST or None, instances=instances)
|
2017-08-26 13:10:18 +00:00
|
|
|
if vlan.is_valid():
|
|
|
|
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()
|
2017-08-26 13:10:18 +00:00
|
|
|
messages.success(request, "Le vlan a été supprimée")
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "Erreur le Vlan suivant %s ne peut être supprimé" % vlan_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-vlan'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'vlanform': vlan, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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()
|
2017-09-10 22:33:45 +00:00
|
|
|
messages.success(request, "Cet enregistrement nas a été ajouté")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-nas'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'nasform': nas, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
2017-09-10 22:33:45 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(Nas)
|
|
|
|
def edit_nas(request, nas_instance, nasid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2017-09-10 22:33:45 +00:00
|
|
|
nas = NasForm(request.POST or None, instance=nas_instance)
|
|
|
|
if nas.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
nas.save()
|
2017-09-10 22:33:45 +00:00
|
|
|
messages.success(request, "Nas modifié")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-nas'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'nasform': nas, 'action_name' : 'Editer'}, 'machines/machine.html', request)
|
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):
|
|
|
|
nas = DelNasForm(request.POST or None, instances=instances)
|
2017-09-10 22:33:45 +00:00
|
|
|
if nas.is_valid():
|
|
|
|
nas_dels = nas.cleaned_data['nas']
|
|
|
|
for nas_del in nas_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
nas_del.delete()
|
2017-09-10 22:33:45 +00:00
|
|
|
messages.success(request, "Le nas a été supprimé")
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(request, "Erreur le Nas suivant %s ne peut être supprimé" % nas_del)
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-nas'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'nasform': nas, 'action_name' : 'Supprimer'}, 'machines/machine.html', request)
|
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):
|
2018-01-30 22:07:43 +00:00
|
|
|
pagination_large_number = GeneralOption.get_cached_value('pagination_large_number')
|
2018-01-31 02:27:59 +00:00
|
|
|
machines_list = Machine.objects.select_related('user').prefetch_related('interface_set__domain__extension').prefetch_related('interface_set__ipv4__ip_type').prefetch_related('interface_set__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
|
|
|
machines_list = SortTable.sort(
|
|
|
|
machines_list,
|
|
|
|
request.GET.get('col'),
|
|
|
|
request.GET.get('order'),
|
|
|
|
SortTable.MACHINES_INDEX
|
|
|
|
)
|
2017-06-25 23:29:34 +00:00
|
|
|
paginator = Paginator(machines_list, pagination_large_number)
|
2016-07-22 01:25:04 +00:00
|
|
|
page = request.GET.get('page')
|
|
|
|
try:
|
|
|
|
machines_list = paginator.page(page)
|
|
|
|
except PageNotAnInteger:
|
|
|
|
# If page is not an integer, deliver first page.
|
|
|
|
machines_list = paginator.page(1)
|
|
|
|
except EmptyPage:
|
|
|
|
# If page is out of range (e.g. 9999), deliver last page of results.
|
|
|
|
machines_list = paginator.page(paginator.num_pages)
|
2016-07-18 03:30:35 +00:00
|
|
|
return render(request, 'machines/index.html', {'machines_list': machines_list})
|
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):
|
2017-10-08 23:29:42 +00:00
|
|
|
iptype_list = IpType.objects.select_related('extension').select_related('vlan').order_by('type')
|
2016-10-22 22:55:58 +00:00
|
|
|
return render(request, 'machines/index_iptype.html', {'iptype_list':iptype_list})
|
|
|
|
|
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):
|
2017-10-08 23:29:42 +00:00
|
|
|
vlan_list = Vlan.objects.prefetch_related('iptype_set').order_by('vlan_id')
|
2017-08-26 13:10:18 +00:00
|
|
|
return render(request, 'machines/index_vlan.html', {'vlan_list':vlan_list})
|
|
|
|
|
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):
|
2017-05-27 02:55:33 +00:00
|
|
|
machinetype_list = MachineType.objects.select_related('ip_type').order_by('type')
|
2016-07-10 02:02:48 +00:00
|
|
|
return render(request, 'machines/index_machinetype.html', {'machinetype_list':machinetype_list})
|
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):
|
2017-10-08 23:29:42 +00:00
|
|
|
nas_list = Nas.objects.select_related('machine_type').select_related('nas_type').order_by('name')
|
2017-09-10 22:33:45 +00:00
|
|
|
return render(request, 'machines/index_nas.html', {'nas_list':nas_list})
|
|
|
|
|
2016-07-08 15:54:06 +00:00
|
|
|
@login_required
|
2017-12-27 00:59:48 +00:00
|
|
|
@can_view_all(SOA)
|
|
|
|
@can_view_all(Mx)
|
|
|
|
@can_view_all(Ns)
|
|
|
|
@can_view_all(Txt)
|
|
|
|
@can_view_all(Srv)
|
|
|
|
@can_view_all(Extension)
|
2016-07-08 15:54:06 +00:00
|
|
|
def index_extension(request):
|
2017-10-19 23:52:38 +00:00
|
|
|
extension_list = Extension.objects.select_related('origin').select_related('soa').order_by('name')
|
|
|
|
soa_list = SOA.objects.order_by('name')
|
2017-05-27 21:54:43 +00:00
|
|
|
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')
|
2017-11-15 14:17:22 +00:00
|
|
|
txt_list = Txt.objects.all().select_related('zone')
|
2017-11-16 01:33:57 +00:00
|
|
|
srv_list = Srv.objects.all().select_related('extension').select_related('target__extension')
|
|
|
|
return render(request, 'machines/index_extension.html', {'extension_list':extension_list, 'soa_list': soa_list, 'mx_list': mx_list, 'ns_list': ns_list, 'txt_list' : txt_list, 'srv_list': srv_list})
|
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):
|
2016-12-24 19:04:53 +00:00
|
|
|
alias_list = Domain.objects.filter(cname=Domain.objects.filter(interface_parent=interface)).order_by('name')
|
2016-11-19 20:15:43 +00:00
|
|
|
return render(request, 'machines/index_alias.html', {'alias_list':alias_list, 'interface_id': interfaceid})
|
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
@login_required
|
|
|
|
@can_edit(Interface)
|
|
|
|
def index_ipv6(request, interface, interfaceid):
|
|
|
|
ipv6_list = Ipv6List.objects.filter(interface=interface)
|
|
|
|
return render(request, 'machines/index_ipv6.html', {'ipv6_list':ipv6_list, 'interface_id': interfaceid})
|
|
|
|
|
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):
|
2017-10-08 23:29:42 +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()
|
2017-08-08 04:56:19 +00:00
|
|
|
return render(request, 'machines/index_service.html', {'service_list':service_list, 'servers_list':servers_list})
|
|
|
|
|
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):
|
2017-10-18 02:11:27 +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')
|
2017-09-29 20:28:48 +00:00
|
|
|
return render(request, "machines/index_portlist.html", {'port_list':port_list})
|
|
|
|
|
2017-09-30 08:04:18 +00:00
|
|
|
@login_required
|
2017-11-30 20:38:16 +00:00
|
|
|
@can_edit(OuverturePortList)
|
|
|
|
def edit_portlist(request, ouvertureportlist_instance, ouvertureportlistid):
|
2017-11-29 23:45:53 +00:00
|
|
|
|
2017-11-30 20:38:16 +00:00
|
|
|
port_list = EditOuverturePortListForm(request.POST or None, instance=ouvertureportlist_instance)
|
2017-10-01 19:57:10 +00:00
|
|
|
port_formset = modelformset_factory(
|
2017-10-07 17:04:23 +00:00
|
|
|
OuverturePort,
|
2017-10-01 19:57:10 +00:00
|
|
|
fields=('begin','end','protocole','io'),
|
|
|
|
extra=0,
|
2017-10-01 21:13:10 +00:00
|
|
|
can_delete=True,
|
|
|
|
min_num=1,
|
|
|
|
validate_min=True,
|
2017-11-30 20:38:16 +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():
|
|
|
|
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()
|
2017-10-01 14:42:55 +00:00
|
|
|
messages.success(request, "Liste de ports modifiée")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-portlist'))
|
2017-10-01 19:57:10 +00:00
|
|
|
return form({'port_list' : port_list, 'ports' : port_formset}, 'machines/edit_portlist.html', request)
|
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)
|
|
|
|
def del_portlist(request, port_list_instance, ouvertureportlistid):
|
2017-10-01 15:09:00 +00:00
|
|
|
port_list_instance.delete()
|
|
|
|
messages.success(request, "La liste de ports a été supprimée")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-portlist'))
|
2017-10-01 15:09:00 +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):
|
2017-11-29 00:53:32 +00:00
|
|
|
|
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(
|
2017-10-07 17:04:23 +00:00
|
|
|
OuverturePort,
|
2017-10-01 20:04:37 +00:00
|
|
|
fields=('begin','end','protocole','io'),
|
2017-10-01 21:13:10 +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()
|
|
|
|
messages.success(request, "Liste de ports créée")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-portlist'))
|
2017-10-01 20:04:37 +00:00
|
|
|
return form({'port_list' : port_list, 'ports' : port_formset}, 'machines/edit_portlist.html', request)
|
2017-10-02 02:19:07 +00:00
|
|
|
port_list = EditOuverturePortListForm(request.POST or None)
|
2017-10-01 15:19:42 +00:00
|
|
|
if port_list.is_valid():
|
|
|
|
port_list.save()
|
|
|
|
messages.success(request, "Liste de ports créée")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index-portlist'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'machineform' : port_list, 'action_name' : 'Créer'}, 'machines/machine.html', request)
|
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)
|
|
|
|
def configure_ports(request, interface_instance, interfaceid):
|
2017-10-02 02:54:40 +00:00
|
|
|
if not interface_instance.may_have_port_open():
|
2017-10-03 04:31:03 +00:00
|
|
|
messages.error(request, "Attention, l'ipv4 n'est pas publique, l'ouverture n'aura pas d'effet en v4")
|
2017-10-02 02:19:07 +00:00
|
|
|
interface = EditOuverturePortConfigForm(request.POST or None, instance=interface_instance)
|
2017-10-01 22:08:07 +00:00
|
|
|
if interface.is_valid():
|
|
|
|
interface.save()
|
|
|
|
messages.success(request, "Configuration des ports mise à jour.")
|
2017-10-26 15:58:41 +00:00
|
|
|
return redirect(reverse('machines:index'))
|
2018-01-31 05:25:39 +00:00
|
|
|
return form({'interfaceform' : interface, 'action_name' : 'Editer la configuration'}, 'machines/machine.html', request)
|
2017-10-01 15:09:00 +00:00
|
|
|
|
2016-07-18 21:22:59 +00:00
|
|
|
""" Framework Rest """
|
|
|
|
|
|
|
|
class JSONResponse(HttpResponse):
|
|
|
|
def __init__(self, data, **kwargs):
|
2016-07-19 19:43:24 +00:00
|
|
|
content = JSONRenderer().render(data)
|
2016-07-18 21:22:59 +00:00
|
|
|
kwargs['content_type'] = 'application/json'
|
|
|
|
super(JSONResponse, self).__init__(content, **kwargs)
|
|
|
|
|
2016-11-11 20:10:10 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2017-02-02 01:21:39 +00:00
|
|
|
def mac_ip_list(request):
|
2017-05-26 23:40:22 +00:00
|
|
|
interfaces = all_active_assigned_interfaces()
|
2017-02-02 01:21:39 +00:00
|
|
|
seria = InterfaceSerializer(interfaces, many=True)
|
2016-07-19 19:43:24 +00:00
|
|
|
return seria.data
|
2016-07-18 21:22:59 +00:00
|
|
|
|
2017-10-03 02:42:49 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2017-10-03 02:42:49 +00:00
|
|
|
def full_mac_ip_list(request):
|
2018-01-30 22:07:43 +00:00
|
|
|
interfaces = all_active_assigned_interfaces(full=True)
|
2017-10-03 02:42:49 +00:00
|
|
|
seria = FullInterfaceSerializer(interfaces, many=True)
|
|
|
|
return seria.data
|
|
|
|
|
2016-11-12 15:12:24 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2016-11-18 17:15:57 +00:00
|
|
|
def alias(request):
|
2017-06-17 19:26:18 +00:00
|
|
|
alias = Domain.objects.filter(interface_parent=None).filter(cname__in=Domain.objects.filter(interface_parent__in=Interface.objects.exclude(ipv4=None))).select_related('extension').select_related('cname__extension')
|
2016-12-24 19:04:53 +00:00
|
|
|
seria = DomainSerializer(alias, many=True)
|
2016-11-18 17:15:57 +00:00
|
|
|
return JSONResponse(seria.data)
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2016-11-18 17:15:57 +00:00
|
|
|
def corresp(request):
|
2017-05-27 21:54:43 +00:00
|
|
|
type = IpType.objects.all().select_related('extension')
|
2016-11-12 15:12:24 +00:00
|
|
|
seria = TypeSerializer(type, many=True)
|
2016-11-18 17:15:57 +00:00
|
|
|
return JSONResponse(seria.data)
|
2016-11-12 15:12:24 +00:00
|
|
|
|
2016-11-20 03:29:16 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2016-11-20 03:29:16 +00:00
|
|
|
def mx(request):
|
2017-05-27 21:54:43 +00:00
|
|
|
mx = Mx.objects.all().select_related('zone').select_related('name__extension')
|
2016-11-20 03:29:16 +00:00
|
|
|
seria = MxSerializer(mx, many=True)
|
|
|
|
return JSONResponse(seria.data)
|
|
|
|
|
2017-09-05 16:18:41 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2017-11-15 14:17:22 +00:00
|
|
|
def txt(request):
|
|
|
|
txt = Txt.objects.all().select_related('zone')
|
|
|
|
seria = TxtSerializer(txt, many=True)
|
2017-09-05 16:18:41 +00:00
|
|
|
return JSONResponse(seria.data)
|
|
|
|
|
2017-11-16 01:33:57 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2017-11-16 01:33:57 +00:00
|
|
|
def srv(request):
|
|
|
|
srv = Srv.objects.all().select_related('extension').select_related('target__extension')
|
|
|
|
seria = SrvSerializer(srv, many=True)
|
|
|
|
return JSONResponse(seria.data)
|
|
|
|
|
2016-11-20 03:29:16 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2016-11-20 03:29:16 +00:00
|
|
|
def ns(request):
|
2017-05-27 21:54:43 +00:00
|
|
|
ns = Ns.objects.exclude(ns__in=Domain.objects.filter(interface_parent__in=Interface.objects.filter(ipv4=None))).select_related('zone').select_related('ns__extension')
|
2016-11-20 03:29:16 +00:00
|
|
|
seria = NsSerializer(ns, many=True)
|
|
|
|
return JSONResponse(seria.data)
|
|
|
|
|
2016-11-20 04:12:36 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2016-11-20 04:12:36 +00:00
|
|
|
def zones(request):
|
2017-05-27 21:54:43 +00:00
|
|
|
zones = Extension.objects.all().select_related('origin')
|
2016-11-20 04:12:36 +00:00
|
|
|
seria = ExtensionSerializer(zones, many=True)
|
|
|
|
return JSONResponse(seria.data)
|
|
|
|
|
2016-11-11 20:10:10 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2016-07-19 19:43:24 +00:00
|
|
|
def mac_ip(request):
|
2017-02-02 01:21:39 +00:00
|
|
|
seria = mac_ip_list(request)
|
2016-07-19 19:43:24 +00:00
|
|
|
return JSONResponse(seria)
|
2016-07-18 21:22:59 +00:00
|
|
|
|
2016-11-11 20:10:10 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2016-10-07 21:40:44 +00:00
|
|
|
def mac_ip_dns(request):
|
2017-10-03 02:42:49 +00:00
|
|
|
seria = full_mac_ip_list(request)
|
2016-07-19 19:43:24 +00:00
|
|
|
return JSONResponse(seria)
|
2016-10-07 21:40:44 +00:00
|
|
|
|
2017-08-08 17:40:30 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2017-08-08 17:40:30 +00:00
|
|
|
def service_servers(request):
|
|
|
|
service_link = Service_link.objects.all().select_related('server__domain').select_related('service')
|
|
|
|
seria = ServiceServersSerializer(service_link, many=True)
|
|
|
|
return JSONResponse(seria.data)
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2017-10-04 20:03:26 +00:00
|
|
|
def ouverture_ports(request):
|
|
|
|
r = {'ipv4':{}, 'ipv6':{}}
|
2017-10-14 10:40:22 +00:00
|
|
|
for o in OuverturePortList.objects.all().prefetch_related('ouvertureport_set').prefetch_related('interface_set', 'interface_set__ipv4'):
|
2017-10-12 19:02:19 +00:00
|
|
|
pl = {
|
2017-10-14 10:40:22 +00:00
|
|
|
"tcp_in":set(map(str,o.ouvertureport_set.filter(protocole=OuverturePort.TCP, io=OuverturePort.IN))),
|
|
|
|
"tcp_out":set(map(str,o.ouvertureport_set.filter(protocole=OuverturePort.TCP, io=OuverturePort.OUT))),
|
|
|
|
"udp_in":set(map(str,o.ouvertureport_set.filter(protocole=OuverturePort.UDP, io=OuverturePort.IN))),
|
|
|
|
"udp_out":set(map(str,o.ouvertureport_set.filter(protocole=OuverturePort.UDP, io=OuverturePort.OUT))),
|
2017-10-12 19:02:19 +00:00
|
|
|
}
|
2017-10-14 10:40:22 +00:00
|
|
|
for i in filter_active_interfaces(o.interface_set):
|
2017-10-12 19:02:19 +00:00
|
|
|
if i.may_have_port_open():
|
|
|
|
d = r['ipv4'].get(i.ipv4.ipv4, {})
|
|
|
|
d["tcp_in"] = d.get("tcp_in",set()).union(pl["tcp_in"])
|
|
|
|
d["tcp_out"] = d.get("tcp_out",set()).union(pl["tcp_out"])
|
|
|
|
d["udp_in"] = d.get("udp_in",set()).union(pl["udp_in"])
|
|
|
|
d["udp_out"] = d.get("udp_out",set()).union(pl["udp_out"])
|
|
|
|
r['ipv4'][i.ipv4.ipv4] = d
|
2018-01-30 06:14:28 +00:00
|
|
|
if i.ipv6():
|
|
|
|
for ipv6 in i.ipv6():
|
|
|
|
d = r['ipv6'].get(ipv6.ipv6, {})
|
|
|
|
d["tcp_in"] = d.get("tcp_in",set()).union(pl["tcp_in"])
|
|
|
|
d["tcp_out"] = d.get("tcp_out",set()).union(pl["tcp_out"])
|
|
|
|
d["udp_in"] = d.get("udp_in",set()).union(pl["udp_in"])
|
|
|
|
d["udp_out"] = d.get("udp_out",set()).union(pl["udp_out"])
|
|
|
|
r['ipv6'][ipv6.ipv6] = d
|
2017-10-04 20:03:26 +00:00
|
|
|
return JSONResponse(r)
|
2018-01-30 06:14:28 +00:00
|
|
|
|
2017-10-04 20:03:26 +00:00
|
|
|
@csrf_exempt
|
|
|
|
@login_required
|
2018-01-06 23:33:52 +00:00
|
|
|
@permission_required('machines.serveur')
|
2017-08-08 17:40:30 +00:00
|
|
|
def regen_achieved(request):
|
2017-08-09 04:08:41 +00:00
|
|
|
obj = Service_link.objects.filter(service__in=Service.objects.filter(service_type=request.POST['service']), server__in=Interface.objects.filter(domain__in=Domain.objects.filter(name=request.POST['server'])))
|
2017-08-08 17:40:30 +00:00
|
|
|
if obj:
|
2017-08-09 04:08:41 +00:00
|
|
|
obj.first().done_regen()
|
2017-08-17 23:01:14 +00:00
|
|
|
return HttpResponse("Ok")
|
2017-08-08 17:40:30 +00:00
|
|
|
|