Commit af6df474 authored by Maël Kervella's avatar Maël Kervella

Merge branch 'master' into faster_ipform

parents 7cc24788 9e0ab9df
This diff is collapsed.
......@@ -109,7 +109,7 @@ def new_facture(request, userid):
return form({'factureform': facture_form, 'venteform': article_formset, 'articlelist': article_list}, 'cotisations/new_facture.html', request)
@login_required
@permission_required('trésorier')
@permission_required('tresorier')
def new_facture_pdf(request):
facture_form = NewFactureFormPdf(request.POST or None)
if facture_form.is_valid():
......@@ -156,7 +156,7 @@ def edit_facture(request, factureid):
except Facture.DoesNotExist:
messages.error(request, u"Facture inexistante" )
return redirect("/cotisations/")
if request.user.has_perms(['trésorier']):
if request.user.has_perms(['tresorier']):
facture_form = TrezEditFactureForm(request.POST or None, instance=facture)
elif facture.control or not facture.valid:
messages.error(request, "Vous ne pouvez pas editer une facture controlée ou invalidée par le trésorier")
......@@ -223,7 +223,7 @@ def credit_solde(request, userid):
@login_required
@permission_required('trésorier')
@permission_required('tresorier')
def add_article(request):
article = ArticleForm(request.POST or None)
if article.is_valid():
......@@ -236,7 +236,7 @@ def add_article(request):
return form({'factureform': article}, 'cotisations/facture.html', request)
@login_required
@permission_required('trésorier')
@permission_required('tresorier')
def edit_article(request, articleid):
try:
article_instance = Article.objects.get(pk=articleid)
......@@ -254,7 +254,7 @@ def edit_article(request, articleid):
return form({'factureform': article}, 'cotisations/facture.html', request)
@login_required
@permission_required('trésorier')
@permission_required('tresorier')
def del_article(request):
article = DelArticleForm(request.POST or None)
if article.is_valid():
......@@ -267,7 +267,7 @@ def del_article(request):
return form({'factureform': article}, 'cotisations/facture.html', request)
@login_required
@permission_required('trésorier')
@permission_required('tresorier')
def add_paiement(request):
paiement = PaiementForm(request.POST or None)
if paiement.is_valid():
......@@ -280,7 +280,7 @@ def add_paiement(request):
return form({'factureform': paiement}, 'cotisations/facture.html', request)
@login_required
@permission_required('trésorier')
@permission_required('tresorier')
def edit_paiement(request, paiementid):
try:
paiement_instance = Paiement.objects.get(pk=paiementid)
......@@ -298,7 +298,7 @@ def edit_paiement(request, paiementid):
return form({'factureform': paiement}, 'cotisations/facture.html', request)
@login_required
@permission_required('trésorier')
@permission_required('tresorier')
def del_paiement(request):
paiement = DelPaiementForm(request.POST or None)
if paiement.is_valid():
......@@ -329,7 +329,7 @@ def add_banque(request):
return form({'factureform': banque}, 'cotisations/facture.html', request)
@login_required
@permission_required('trésorier')
@permission_required('tresorier')
def edit_banque(request, banqueid):
try:
banque_instance = Banque.objects.get(pk=banqueid)
......@@ -347,7 +347,7 @@ def edit_banque(request, banqueid):
return form({'factureform': banque}, 'cotisations/facture.html', request)
@login_required
@permission_required('trésorier')
@permission_required('tresorier')
def del_banque(request):
banque = DelBanqueForm(request.POST or None)
if banque.is_valid():
......@@ -365,7 +365,7 @@ def del_banque(request):
return form({'factureform': banque}, 'cotisations/facture.html', request)
@login_required
@permission_required('trésorier')
@permission_required('tresorier')
def control(request):
options, created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number
......
......@@ -257,12 +257,15 @@ def check_user_machine_and_register(nas_type, username, mac_address):
return (True, u'Access Ok, Capture de la mac...', user.pwd_ntlm)
else:
return (False, u'Erreur dans le register mac %s' % reason, '')
else:
return (False, u'Machine inconnue', '')
else:
return (False, u"Machine inconnue", '')
def decide_vlan_and_register_switch(nas, nas_type, port_number, mac_address):
# Get port from switch and port number
extra_log = ""
if not nas:
return ('?', u'Nas inconnu', VLAN_OK)
......@@ -273,9 +276,15 @@ def decide_vlan_and_register_switch(nas, nas_type, port_number, mac_address):
return (sw_name, u'Port inconnu', VLAN_OK)
port = port.first()
# Si un vlan a été précisé, on l'utilise pour VLAN_OK
if port.vlan_force:
DECISION_VLAN = int(port.vlan_force.vlan_id)
extra_log = u"Force sur vlan " + str(DECISION_VLAN)
else:
DECISION_VLAN = VLAN_OK
if port.radius == 'NO':
return (sw_name, u"Pas d'authentification sur ce port", VLAN_OK)
return (sw_name, u"Pas d'authentification sur ce port" + extra_log, DECISION_VLAN)
if port.radius == 'BLOQ':
return (sw_name, u'Port desactive', VLAN_NOK)
......@@ -309,16 +318,12 @@ def decide_vlan_and_register_switch(nas, nas_type, port_number, mac_address):
else:
result, reason = room_user.first().autoregister_machine(mac_address, nas_type)
if result:
return (sw_name, u'Access Ok, Capture de la mac...', VLAN_OK)
return (sw_name, u'Access Ok, Capture de la mac...' + extra_log, DECISION_VLAN)
else:
return (sw_name, u'Erreur dans le register mac %s' % reason + unicode(mac_address), VLAN_NOK)
elif not interface.first().is_active:
return (sw_name, u'Machine non active / adherent non cotisant', VLAN_NOK)
else:
return (sw_name, u'Machine OK', VLAN_OK)
# On gere bien tous les autres états possibles, il ne reste que le VLAN en dur
return (sw_name, u'VLAN impose', int(port.radius))
return (sw_name, u'Machine OK' + extra_log, DECISION_VLAN)
......@@ -106,7 +106,7 @@ def index(request):
'user_id': v.revision.user_id,
'version': v }
else :
to_remove.append(i)
to_remove.insert(0,i)
# Remove all tagged invalid items
for i in to_remove :
versions.object_list.pop(i)
......
......@@ -26,7 +26,9 @@ from __future__ import unicode_literals
from django.contrib import admin
from reversion.admin import VersionAdmin
from .models import IpType, Machine, MachineType, Domain, IpList, Interface, Extension, Mx, Ns, Vlan, Text, Nas, Service
from .models import IpType, Machine, MachineType, Domain, IpList, Interface
from .models import Extension, Mx, Ns, Vlan, Text, Nas, Service, OuverturePort
from .models import OuverturePortList
class MachineAdmin(VersionAdmin):
pass
......@@ -58,6 +60,12 @@ class NasAdmin(VersionAdmin):
class IpListAdmin(VersionAdmin):
pass
class OuverturePortAdmin(VersionAdmin):
pass
class OuverturePortListAdmin(VersionAdmin):
pass
class InterfaceAdmin(VersionAdmin):
list_display = ('machine','type','mac_address','ipv4','details')
......@@ -80,3 +88,7 @@ admin.site.register(Domain, DomainAdmin)
admin.site.register(Service, ServiceAdmin)
admin.site.register(Vlan, VlanAdmin)
admin.site.register(Nas, NasAdmin)
admin.site.register(OuverturePort, OuverturePortAdmin)
admin.site.register(OuverturePortList, OuverturePortListAdmin)
......@@ -24,9 +24,11 @@
from __future__ import unicode_literals
import re
from django.forms import ModelForm, Form, ValidationError
from django import forms
from .models import Domain, Machine, Interface, IpList, MachineType, Extension, Mx, Text, Ns, Service, Vlan, Nas, IpType
from .models import Domain, Machine, Interface, IpList, MachineType, Extension, Mx, Text, Ns, Service, Vlan, Nas, IpType, OuverturePortList, OuverturePort
from django.db.models import Q, F
from django.core.validators import validate_email
......@@ -116,11 +118,11 @@ class DomainForm(AliasForm):
fields = ['name']
def __init__(self, *args, **kwargs):
if 'name_user' in kwargs:
name_user = kwargs.pop('name_user')
if 'user' in kwargs:
user = kwargs.pop('user')
nb_machine = kwargs.pop('nb_machine')
initial = kwargs.get('initial', {})
initial['name'] = name_user.lower()+str(nb_machine)
initial['name'] = user.get_next_domain_name()
kwargs['initial'] = initial
super(DomainForm, self).__init__(*args, **kwargs)
......@@ -148,7 +150,7 @@ class DelMachineTypeForm(Form):
class IpTypeForm(ModelForm):
class Meta:
model = IpType
fields = ['type','extension','need_infra','domaine_ip_start','domaine_ip_stop', 'vlan']
fields = ['type','extension','need_infra','domaine_ip_start','domaine_ip_stop', 'prefix_v6', 'vlan']
def __init__(self, *args, **kwargs):
......@@ -157,7 +159,7 @@ class IpTypeForm(ModelForm):
class EditIpTypeForm(IpTypeForm):
class Meta(IpTypeForm.Meta):
fields = ['extension','type','need_infra', 'vlan']
fields = ['extension','type','need_infra', 'prefix_v6', 'vlan']
class DelIpTypeForm(Form):
iptypes = forms.ModelMultipleChoiceField(queryset=IpType.objects.all(), label="Types d'ip actuelles", widget=forms.CheckboxSelectMultiple)
......@@ -238,5 +240,13 @@ class VlanForm(ModelForm):
class DelVlanForm(Form):
vlan = forms.ModelMultipleChoiceField(queryset=Vlan.objects.all(), label="Vlan actuels", widget=forms.CheckboxSelectMultiple)
class EditOuverturePortConfigForm(ModelForm):
class Meta:
model = Interface
fields = ['port_lists']
class EditOuverturePortListForm(ModelForm):
class Meta:
model = OuverturePortList
fields = '__all__'
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-10-02 01:50
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('machines', '0057_nas_autocapture_mac'),
]
operations = [
migrations.CreateModel(
name='OuverturePort',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('begin', models.IntegerField()),
('end', models.IntegerField()),
('protocole', models.CharField(choices=[('T', 'TCP'), ('U', 'UDP')], default='T', max_length=1)),
('io', models.CharField(choices=[('I', 'IN'), ('O', 'OUT')], default='O', max_length=1)),
],
),
migrations.CreateModel(
name='OuverturePortList',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(help_text='Nom de la configuration des ports.', max_length=255)),
],
),
migrations.AddField(
model_name='ouvertureport',
name='port_list',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='machines.OuverturePortList'),
),
migrations.AddField(
model_name='interface',
name='port_lists',
field=models.ManyToManyField(blank=True, to='machines.OuverturePortList'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-10-02 16:33
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0058_auto_20171002_0350'),
]
operations = [
migrations.AddField(
model_name='iptype',
name='prefix_v6',
field=models.GenericIPAddressField(blank=True, null=True, protocol='IPv6'),
),
]
This diff is collapsed.
......@@ -56,6 +56,25 @@ class InterfaceSerializer(serializers.ModelSerializer):
def get_macaddress(self, obj):
return str(obj.mac_address)
class FullInterfaceSerializer(serializers.ModelSerializer):
ipv4 = IpListSerializer(read_only=True)
mac_address = serializers.SerializerMethodField('get_macaddress')
domain = serializers.SerializerMethodField('get_dns')
extension = serializers.SerializerMethodField('get_interface_extension')
class Meta:
model = Interface
fields = ('ipv4', 'ipv6', 'mac_address', 'domain', 'extension')
def get_dns(self, obj):
return obj.domain.name
def get_interface_extension(self, obj):
return obj.domain.extension.name
def get_macaddress(self, obj):
return str(obj.mac_address)
class ExtensionNameField(serializers.RelatedField):
def to_representation(self, value):
return value.name
......
......@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Nécessite l'autorisation infra</th>
<th>Début</th>
<th>Fin</th>
<th>Préfixe v6</th>
<th>Sur vlan</th>
<th></th>
<th></th>
......@@ -42,6 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ type.need_infra }}</td>
<td>{{ type.domaine_ip_start }}</td>
<td>{{ type.domaine_ip_stop }}</td>
<td>{{ type.prefix_v6 }}</td>
<td>{{ type.vlan }}</td>
<td class="text-right">
{% if is_infra %}
......
......@@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Nom dns</th>
<th>Type</th>
<th>Mac</th>
<th>Ipv4</th>
<th>IP</th>
<th></th>
</tr>
</thead>
......@@ -74,7 +74,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</td>
<td>{{ interface.type }}</td>
<td>{{ interface.mac_address }}</td>
<td>{{ interface.ipv4 }}</td>
<td><b>IPv4</b> {{ interface.ipv4 }}
{% if ipv6_enabled %}
<br>
<b>IPv6</b> {{ interface.ipv6 }}
{% endif %}
</td>
<td>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="editioninterface" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
......@@ -91,6 +96,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<i class="glyphicon glyphicon-edit"></i> Gerer les alias
</a>
</li>
<li>
<a href="{% url 'machines:port-config' interface.id%}">
<i class="glyphicon glyphicon-edit"></i> Gerer la configuration des ports
</a>
</li>
<li>
<a href="{% url 'machines:history' 'interface' interface.id %}">
<i class="glyphicon glyphicon-time"></i> Historique
......
{% extends "machines/sidebar.html" %}
{% comment %}
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
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.
{% endcomment %}
{% load bootstrap3 %}
{% block title %}Création et modification de machines{% endblock %}
{% block content %}
{% bootstrap_form_errors port_list %}
<form class="form" method="post">
{% csrf_token %}
{% bootstrap_form port_list %}
{{ ports.management_form }}
<div id="formset">
{% for form in ports.forms %}
<div class="port">
<p>
{{ form }}
</p>
</div>
{% endfor %}
</div>
<p>
<input class="btn btn-primary btn-sm" role="button" value="Ajouter un port" id="add_one">
</p>
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form>
<script type="text/javascript">
var template = `{{ports.empty_form}}`;
function add_port(){
var new_index = document.getElementsByClassName('port').length;
document.getElementById('id_form-TOTAL_FORMS').value =
parseInt(document.getElementById('id_form-TOTAL_FORMS').value) + 1;
var new_port = document.createElement('div');
new_port.className = 'port';
new_port.innerHTML = template.replace(/__prefix__/g, new_index);
document.getElementById('formset').appendChild(new_port);
}
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("add_one").addEventListener("click", add_port, true);});
</script>
{% endblock %}
{% extends "machines/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Configuration de ports{% endblock %}
{% block content %}
<h2>Liste des configurations de ports</h2>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-portlist' %}"><i class="glyphicon glyphicon-plus"></i>Ajouter une configuration</a>
<table class="table table-striped">
<thead>
<tr>
<th>Nom</th>
<th>TCP (entrée)</th>
<th>TCP (sortie)</th>
<th>UDP (entrée)</th>
<th>UDP (sortie)</th>
<th>Machines</th>
<th></th>
</tr>
</thead>
{% for pl in port_list %}
<tr>
<td>{{pl.name}}</td>
<td>{% for p in pl.tcp_ports_in %}{{p.show_port}}, {%endfor%}</td>
<td>{% for p in pl.tcp_ports_out %}{{p.show_port}}, {%endfor%}</td>
<td>{% for p in pl.udp_ports_in %}{{p.show_port}}, {%endfor%}</td>
<td>{% for p in pl.udp_ports_out %}{{p.show_port}}, {%endfor%}</td>
<td>
{% if pl.interface_set.all %}
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="editioninterface" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="editioninterface">
{% for interface in pl.interface_set.all %}
<li>
<a href="{% url 'users:profil' userid=interface.machine.user.id %}">
{{ interface }}
</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
<td class="text-right">
{% include 'buttons/suppr.html' with href='machines:del-portlist' id=pl.id %}
{% include 'buttons/edit.html' with href='machines:edit-portlist' id=pl.id %}
</td>
</tr>
{%endfor%}
</table>
<br />
<br />
<br />
{% endblock %}
......@@ -55,4 +55,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Services (dhcp, dns...)
</a>
{% endif %}
{% if is_cableur %}
<a class="list-group-item list-group-item-info" href="{% url "machines:index-portlist" %}">
<i class="glyphicon glyphicon-list"></i>
Configuration de ports
</a>
{%endif%}
{% endblock %}
......@@ -93,4 +93,10 @@ urlpatterns = [
url(r'^rest/text/$', views.text, name='text'),
url(r'^rest/zones/$', views.zones, name='zones'),
url(r'^rest/service_servers/$', views.service_servers, name='service-servers'),
url(r'index_portlist/$', views.index_portlist, name='index-portlist'),
url(r'^edit_portlist/(?P<pk>[0-9]+)$', views.edit_portlist, name='edit-portlist'),
url(r'^del_portlist/(?P<pk>[0-9]+)$', views.del_portlist, name='del-portlist'),
url(r'^add_portlist/$', views.add_portlist, name='add-portlist'),
url(r'^port_config/(?P<pk>[0-9]+)$', views.configure_ports, name='port-config'),
]
......@@ -37,20 +37,21 @@ from django.template import Context, RequestContext, loader
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.db.models import ProtectedError
from django.forms import ValidationError
from django.forms import ValidationError, modelformset_factory
from django.db import transaction
from django.contrib.auth import authenticate, login
from django.views.decorators.csrf import csrf_exempt
from rest_framework.renderers import JSONRenderer
from machines.serializers import InterfaceSerializer, TypeSerializer, DomainSerializer, TextSerializer, MxSerializer, ExtensionSerializer, ServiceServersSerializer, NsSerializer
from machines.serializers import FullInterfaceSerializer, InterfaceSerializer, TypeSerializer, DomainSerializer, TextSerializer, MxSerializer, ExtensionSerializer, ServiceServersSerializer, NsSerializer
from reversion import revisions as reversion
from reversion.models import Version
import re
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm
from .forms import EditIpTypeForm, IpTypeForm, DelIpTypeForm, DomainForm, AliasForm, DelAliasForm, NsForm, DelNsForm, TextForm, DelTextForm, MxForm, DelMxForm, VlanForm, DelVlanForm, ServiceForm, DelServiceForm, NasForm, DelNasForm
from .models import IpType, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, Domain, Service, Service_link, Vlan, Nas, Text
from .forms import EditOuverturePortListForm, EditOuverturePortConfigForm
from .models import IpType, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, Domain, Service, Service_link, Vlan, Nas, Text, OuverturePortList, OuverturePort
from users.models import User
from users.models import all_has_access
from preferences.models import GeneralOption, OptionalMachine
......@@ -132,7 +133,7 @@ def new_machine(request, userid):
machine = NewMachineForm(request.POST or None)
interface = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',)))
nb_machine = Interface.objects.filter(machine__user=userid).count()
domain = DomainForm(request.POST or None, name_user=user.pseudo.replace('_','-'), nb_machine=nb_machine)
domain = DomainForm(request.POST or None, user=user, nb_machine=nb_machine)
if machine.is_valid() and interface.is_valid():
new_machine = machine.save(commit=False)
new_machine.user = user
......@@ -957,6 +958,103 @@ def history(request, object, id):
return render(request, 're2o/history.html', {'reversions': reversions, 'object': object_instance})
@login_required
@permission_required('cableur')
def index_portlist(request):
port_list = OuverturePortList.objects.all().order_by('name')
return render(request, "machines/index_portlist.html", {'port_list':port_list})
@login_required
@permission_required('bureau')
def edit_portlist(request, pk):
try:
port_list_instance = OuverturePortList.objects.get(pk=pk)
except OuverturePortList.DoesNotExist:
messages.error(request, "Liste de ports inexistante")
return redirect("/machines/index_portlist/")
port_list = EditOuverturePortListForm(request.POST or None, instance=port_list_instance)
port_formset = modelformset_factory(
OuverturePort,
fields=('begin','end','protocole','io'),
extra=0,
can_delete=True,
min_num=1,
validate_min=True,
)(request.POST or None, queryset=port_list_instance.ouvertureport_set.all())
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 modifiée")
return redirect("/machines/index_portlist/")
return form({'port_list' : port_list, 'ports' : port_formset}, 'machines/edit_portlist.html', request)
@login_required
@permission_required('bureau')
def del_portlist(request, pk):
try:
port_list_instance = OuverturePortList.objects.get(pk=pk)
except OuverturePortList.DoesNotExist:
messages.error(request, "Liste de ports inexistante")
return redirect("/machines/index_portlist/")
if port_list_instance.interface_set.all():
messages.error(request, "Cette liste de ports est utilisée")
return redirect("/machines/index_portlist/")
port_list_instance.delete()
messages.success(request, "La liste de ports a été supprimée")
return redirect("/machines/index_portlist/")
@login_required
@permission_required('bureau')
def add_portlist(request):
port_list = EditOuverturePortListForm(request.POST or None)
port_formset = modelformset_factory(
OuverturePort,
fields=('begin','end','protocole','io'),
extra=0,
can_delete=True,
min_num=1,
validate_min=True,
)(request.POST or None, queryset=OuverturePort.objects.none())
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")
return redirect("/machines/index_portlist/")
return form({'port_list' : port_list, 'ports' : port_formset}, 'machines/edit_portlist.html', request)
port_list = EditOuverturePortListForm(request.POST or None)
if port_list.is_valid():
port_list.save()
messages.success(request, "Liste de ports créée")
return redirect("/machines/index_portlist/")
return form({'machineform' : port_list}, 'machines/machine.html', request)
@login_required
@permission_required('cableur')
def configure_ports(request, pk):
try:
interface_instance = Interface.objects.get(pk=pk)
except Interface.DoesNotExist:
messages.error(request, u"Interface inexistante" )
return redirect("/machines")
if not interface_instance.may_have_port_open():
messages.error(request, "Attention, l'ipv4 n'est pas publique, l'ouverture n'aura pas d'effet en v4")
interface = EditOuverturePortConfigForm(request.POST or None, instance=interface_instance)
if interface.is_valid():
interface.save()
messages.success(request, "Configuration des ports mise à jour.")
return redirect("/machines/")
return form({'interfaceform' : interface}, 'machines/machine.html', request)
""" Framework Rest """
class JSONResponse(HttpResponse):
......@@ -973,6 +1071,14 @@ def mac_ip_list(request):
seria = InterfaceSerializer(interfaces, many=True)
return seria.data
@csrf_exempt
@login_required
@permission_required('serveur')
def full_mac_ip_list(request):
interfaces = all_active_assigned_interfaces()
seria = FullInterfaceSerializer(interfaces, many=True)
return seria.data
@csrf_exempt
@login_required
@permission_required('serveur')
......@@ -1032,7 +1138,7 @@ def mac_ip(request):
@login_required
@permission_required('serveur')
def mac_ip_dns(request):
seria = mac_ip_list(request)
seria = full_mac_ip_list(request)
return JSONResponse(seria)
@csrf_exempt
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-10-02 16:14
from __future__ import unicode_literals
from django.db import migrations, models