Le serveur gitlab sera inaccessible le mercredi 19 février 2020 de 13h à 14h pour une intervention de maintenance programmée.

Commit 623be9ac authored by Charlie Jacomme's avatar Charlie Jacomme Committed by chirac

Specify range for autocapture

parent cd8a23da
......@@ -397,7 +397,10 @@ class IpType(RevMixin, AclMixin, models.Model):
def complete_prefixv6(self):
"""Return the complete prefix v6 as cidr"""
if self.prefix_v6:
return str(self.prefix_v6) + "/" + str(self.prefix_v6_length)
return None
def ip_objects(self):
""" Renvoie tous les objets ipv4 relié à ce type"""
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-08-31 14:37
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0094_auto_20180815_1918'),
('preferences', '0050_auto_20180818_1329'),
operations = [
field=models.ManyToManyField(blank=True, help_text="Définit la plage d'ip depuis laquel un utilisateur peut enregistrer une machine filaire", to='machines.IpType'),
......@@ -149,6 +149,13 @@ class OptionalMachine(AclMixin, PreferencesModel):
autocapture_iprange = models.ManyToManyField(
help_text=_("Définit la plage d'ip depuis laquel un utilisateur peut enregistrer une machine filaire"),
def ipv6(self):
""" Check if the IPv6 option is activated """
......@@ -96,6 +96,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>{% trans "Creation of machines" %}</th>
<td>{{ machineoptions.create_machine|tick }}</td>
<th>{% trans "IPs range d'autoregister" %}</th>
<td>{% for type in machineoptions.autocapture_iprange.all %}
{% endfor %}
<h4>{% trans "Topology preferences" %}</h4>
......@@ -47,13 +47,14 @@ from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.views.decorators.csrf import csrf_exempt
from django.utils.translation import ugettext as _
from django.core.exceptions import PermissionDenied
from rest_framework.renderers import JSONRenderer
from reversion import revisions as reversion
from cotisations.models import Facture, Paiement
from machines.models import Machine
from preferences.models import OptionalUser, GeneralOption, AssoOption
from preferences.models import OptionalUser, OptionalMachine, GeneralOption, AssoOption
from re2o.views import form
from re2o.utils import (
......@@ -71,6 +72,8 @@ from re2o.acl import (
from cotisations.utils import find_payment_method
from netaddr import IPAddress, IPNetwork
from .serializers import MailingSerializer, MailingMemberSerializer
from .models import (
......@@ -1084,6 +1087,8 @@ def process_passwd(request, req):
def initial_register(request):
options, created = OptionalMachine.objects.get_or_create()
if any(IPAddress(request.META['REMOTE_ADDR']) in t.ip_set for t in options.autocapture_iprange.all()) or any(IPAddress(request.META['REMOTE_ADDR']) in IPNetwork(t.complete_prefixv6) for t in options.autocapture_iprange.all() if t.complete_prefixv6 ):
u_form = InitialRegisterForm(request.POST or None, user=request.user, switch_ip=request.GET.get('switch_ip', None), switch_port=request.GET.get('switch_port', None), client_mac=request.GET.get('client_mac', None))
if not u_form.fields:
messages.error(request, _("Incorrect URL, or already registered device"))
......@@ -1105,6 +1110,8 @@ def initial_register(request):
raise PermissionDenied
class JSONResponse(HttpResponse):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment