diff --git a/cotisations/models.py b/cotisations/models.py
index 692ff3a2..60e8672e 100644
--- a/cotisations/models.py
+++ b/cotisations/models.py
@@ -49,7 +49,7 @@ class Facture(models.Model):
return Vente.objects.filter(facture=self).aggregate(total=models.Sum(models.F('prix')*models.F('number'), output_field=models.FloatField()))['total']
def name(self):
- name = ' - '.join(vente.name for vente in Vente.objects.filter(facture=self))
+ name = ' - '.join(Vente.objects.filter(facture=self).values_list('name', flat=True))
return name
def __str__(self):
diff --git a/freeradius_utils/authenticate_filaire.py b/freeradius_utils/authenticate_filaire.py
index 40c38ef2..1fe82209 100755
--- a/freeradius_utils/authenticate_filaire.py
+++ b/freeradius_utils/authenticate_filaire.py
@@ -40,11 +40,12 @@ from django.db.models import Q
from machines.models import Interface, IpList, Domain
from topologie.models import Room, Port, Switch
from users.models import User
+from preferences.models import OptionalTopologie
-from re2o.settings import RADIUS_VLAN_DECISION
+options, created = OptionalTopologie.objects.get_or_create()
+VLAN_NOK = options.vlan_decision_nok.vlan_id
+VLAN_OK = options.vlan_decision_ok.vlan_id
-VLAN_NOK = RADIUS_VLAN_DECISION['VLAN_NOK']
-VLAN_OK = RADIUS_VLAN_DECISION['VLAN_OK']
def decide_vlan(switch_id, port_number, mac_address):
# Get port from switch and port number
diff --git a/machines/admin.py b/machines/admin.py
index 147fca0f..c9559fe5 100644
--- a/machines/admin.py
+++ b/machines/admin.py
@@ -23,29 +23,31 @@
from django.contrib import admin
from reversion.admin import VersionAdmin
-from .models import IpType, Machine, MachineType, Domain, IpList, Interface, Extension, Mx, Ns, Service
+from .models import IpType, Machine, MachineType, Domain, IpList, Interface, Extension, Mx, Ns, Vlan, Service
class MachineAdmin(VersionAdmin):
- list_display = ('user','name','active')
+ pass
class IpTypeAdmin(VersionAdmin):
- list_display = ('type','extension','need_infra','domaine_ip','domaine_range')
+ pass
class MachineTypeAdmin(VersionAdmin):
- list_display = ('type','ip_type')
+ pass
+class VlanAdmin(VersionAdmin):
+ pass
class ExtensionAdmin(VersionAdmin):
- list_display = ('name','origin')
+ pass
class MxAdmin(VersionAdmin):
- list_display = ('zone', 'priority', 'name')
+ pass
class NsAdmin(VersionAdmin):
- list_display = ('zone', 'ns')
+ pass
class IpListAdmin(VersionAdmin):
- list_display = ('ipv4','ip_type')
+ pass
class InterfaceAdmin(VersionAdmin):
list_display = ('machine','type','mac_address','ipv4','details')
@@ -66,3 +68,4 @@ admin.site.register(IpList, IpListAdmin)
admin.site.register(Interface, InterfaceAdmin)
admin.site.register(Domain, DomainAdmin)
admin.site.register(Service, ServiceAdmin)
+admin.site.register(Vlan, VlanAdmin)
diff --git a/machines/forms.py b/machines/forms.py
index 64f4f3af..3512e277 100644
--- a/machines/forms.py
+++ b/machines/forms.py
@@ -22,7 +22,7 @@
from django.forms import ModelForm, Form, ValidationError
from django import forms
-from .models import Domain, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, Service, IpType
+from .models import Domain, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, Service, Vlan, IpType
from django.db.models import Q
from django.core.validators import validate_email
@@ -143,7 +143,7 @@ class DelMachineTypeForm(Form):
class IpTypeForm(ModelForm):
class Meta:
model = IpType
- fields = ['type','extension','need_infra','domaine_ip','domaine_range']
+ fields = ['type','extension','need_infra','domaine_ip','domaine_range', 'vlan']
def __init__(self, *args, **kwargs):
super(IpTypeForm, self).__init__(*args, **kwargs)
@@ -151,7 +151,7 @@ class IpTypeForm(ModelForm):
class EditIpTypeForm(IpTypeForm):
class Meta(IpTypeForm.Meta):
- fields = ['extension','type','need_infra']
+ fields = ['extension','type','need_infra', 'vlan']
class DelIpTypeForm(Form):
iptypes = forms.ModelMultipleChoiceField(queryset=IpType.objects.all(), label="Types d'ip actuelles", widget=forms.CheckboxSelectMultiple)
@@ -208,3 +208,13 @@ class ServiceForm(ModelForm):
class DelServiceForm(Form):
service = forms.ModelMultipleChoiceField(queryset=Service.objects.all(), label="Services actuels", widget=forms.CheckboxSelectMultiple)
+class VlanForm(ModelForm):
+ class Meta:
+ model = Vlan
+ fields = '__all__'
+
+class DelVlanForm(Form):
+ vlan = forms.ModelMultipleChoiceField(queryset=Vlan.objects.all(), label="Vlan actuels", widget=forms.CheckboxSelectMultiple)
+
+
+
diff --git a/machines/migrations/0049_vlan.py b/machines/migrations/0049_vlan.py
new file mode 100644
index 00000000..20a6905b
--- /dev/null
+++ b/machines/migrations/0049_vlan.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.7 on 2017-08-25 21:07
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('machines', '0048_auto_20170823_2315'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Vlan',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('vlan_id', models.IntegerField()),
+ ('name', models.CharField(max_length=256)),
+ ('comment', models.CharField(max_length=256)),
+ ],
+ ),
+ ]
diff --git a/machines/migrations/0050_auto_20170826_0022.py b/machines/migrations/0050_auto_20170826_0022.py
new file mode 100644
index 00000000..0f49a08b
--- /dev/null
+++ b/machines/migrations/0050_auto_20170826_0022.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.7 on 2017-08-25 22:22
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('machines', '0049_vlan'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='vlan',
+ name='comment',
+ field=models.CharField(blank=True, max_length=256),
+ ),
+ ]
diff --git a/machines/migrations/0051_iptype_vlan.py b/machines/migrations/0051_iptype_vlan.py
new file mode 100644
index 00000000..27b641b2
--- /dev/null
+++ b/machines/migrations/0051_iptype_vlan.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.7 on 2017-08-25 23:04
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('machines', '0050_auto_20170826_0022'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='iptype',
+ name='vlan',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='machines.Vlan'),
+ ),
+ ]
diff --git a/machines/models.py b/machines/models.py
index 9da62f5e..0866d4dc 100644
--- a/machines/models.py
+++ b/machines/models.py
@@ -69,6 +69,7 @@ class IpType(models.Model):
need_infra = models.BooleanField(default=False)
domaine_ip = models.GenericIPAddressField(protocol='IPv4')
domaine_range = models.IntegerField(validators=[MinValueValidator(16), MaxValueValidator(32)])
+ vlan = models.ForeignKey('Vlan', on_delete=models.PROTECT, blank=True, null=True)
@cached_property
def network(self):
@@ -107,7 +108,7 @@ class IpType(models.Model):
def clean(self):
# On check que les / ne se recoupent pas
- for element in IpType.objects.all():
+ for element in IpType.objects.all().exclude(pk=self.pk):
if not self.ip_set.isdisjoint(element.ip_set):
raise ValidationError("Le range indiqué n'est pas disjoint des ranges existants")
return
@@ -119,6 +120,16 @@ class IpType(models.Model):
def __str__(self):
return self.type
+class Vlan(models.Model):
+ PRETTY_NAME = "Vlans"
+
+ vlan_id = models.IntegerField()
+ name = models.CharField(max_length=256)
+ comment = models.CharField(max_length=256, blank=True)
+
+ def __str__(self):
+ return self.name
+
class Extension(models.Model):
PRETTY_NAME = "Extensions dns"
@@ -360,7 +371,8 @@ def interface_post_delete(sender, **kwargs):
@receiver(post_save, sender=IpType)
def iptype_post_save(sender, **kwargs):
iptype = kwargs['instance']
- iptype.gen_ip_range()
+ if not iptype.ip_objects():
+ iptype.gen_ip_range()
@receiver(post_save, sender=MachineType)
def machine_post_save(sender, **kwargs):
diff --git a/machines/templates/machines/aff_iptype.html b/machines/templates/machines/aff_iptype.html
index 0bcb11b5..c0f6b880 100644
--- a/machines/templates/machines/aff_iptype.html
+++ b/machines/templates/machines/aff_iptype.html
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Nécessite l'autorisation infra |
Domaine d'ip |
Range |
+ Sur vlan |
|
|
@@ -41,6 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{{ type.need_infra }} |
{{ type.domaine_ip }} |
{{ type.domaine_range }} |
+ {{ type.vlan }} |
{% if is_infra %}
{% include 'buttons/edit.html' with href='machines:edit-iptype' id=type.id %}
diff --git a/machines/templates/machines/aff_vlan.html b/machines/templates/machines/aff_vlan.html
new file mode 100644
index 00000000..eaa1c82c
--- /dev/null
+++ b/machines/templates/machines/aff_vlan.html
@@ -0,0 +1,50 @@
+{% 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 %}
+
+
+
+
+ Id |
+ Nom |
+ Commentaire |
+ Ranges ip |
+ |
+
+
+ {% for vlan in vlan_list %}
+
+ {{ vlan.vlan_id }} |
+ {{ vlan.name }} |
+ {{ vlan.comment }} |
+ {% for range in vlan.iptype_set.all %}{{ range }}, {% endfor%} |
+
+ {% if is_infra %}
+ {% include 'buttons/edit.html' with href='machines:edit-vlan' id=vlan.id %}
+ {% endif %}
+ {% include 'buttons/history.html' with href='machines:history' name='vlan' id=vlan.id %}
+ |
+
+ {% endfor %}
+
+
diff --git a/machines/templates/machines/index_vlan.html b/machines/templates/machines/index_vlan.html
new file mode 100644
index 00000000..ccbfa753
--- /dev/null
+++ b/machines/templates/machines/index_vlan.html
@@ -0,0 +1,39 @@
+{% 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 %}Machines{% endblock %}
+
+{% block content %}
+ Liste des vlans
+ Ajouter un vlan
+ Supprimer un ou plusieurs vlan
+ {% include "machines/aff_vlan.html" with vlan_list=vlan_list %}
+
+
+
+{% endblock %}
+
diff --git a/machines/templates/machines/sidebar.html b/machines/templates/machines/sidebar.html
index c4d98448..25c108cb 100644
--- a/machines/templates/machines/sidebar.html
+++ b/machines/templates/machines/sidebar.html
@@ -42,6 +42,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Plages d'IP
+
+
+ Vlans
+
Services (dhcp, dns...)
diff --git a/machines/urls.py b/machines/urls.py
index b35e9d6f..07ad6129 100644
--- a/machines/urls.py
+++ b/machines/urls.py
@@ -56,6 +56,10 @@ urlpatterns = [
url(r'^edit_service/(?P[0-9]+)$', views.edit_service, name='edit-service'),
url(r'^del_service/$', views.del_service, name='del-service'),
url(r'^index_service/$', views.index_service, name='index-service'),
+ url(r'^add_vlan/$', views.add_vlan, name='add-vlan'),
+ url(r'^edit_vlan/(?P[0-9]+)$', views.edit_vlan, name='edit-vlan'),
+ url(r'^del_vlan/$', views.del_vlan, name='del-vlan'),
+ url(r'^index_vlan/$', views.index_vlan, name='index-vlan'),
url(r'^history/(?P |