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):
@cached_property
def complete_prefixv6(self):
"""Return the complete prefix v6 as cidr"""
return str(self.prefix_v6) + "/" + str(self.prefix_v6_length)
if self.prefix_v6:
return str(self.prefix_v6) + "/" + str(self.prefix_v6_length)
else:
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 = [
migrations.AddField(
model_name='optionalmachine',
name='autocapture_iprange',
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):
default=True
)
autocapture_iprange = models.ManyToManyField(
'machines.IpType',
help_text=_("Définit la plage d'ip depuis laquel un utilisateur peut enregistrer une machine filaire"),
blank=True,
)
@cached_property
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.,
<tr>
<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 %}
{{type.type}}
{% endfor %}
</td>
</tr>
</table>
<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 (
all_has_access,
......@@ -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 (
User,
......@@ -1084,27 +1087,31 @@ def process_passwd(request, req):
@login_required
def initial_register(request):
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"))
return redirect(reverse(
'users:profil',
kwargs={'userid': str(request.user.id)}
))
if u_form.is_valid():
messages.success(request, _("Successful registration! Please"
" disconnect and reconnect your Ethernet"
" cable to get Internet access."))
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"))
return redirect(reverse(
'users:profil',
kwargs={'userid': str(request.user.id)}
))
if u_form.is_valid():
messages.success(request, _("Successful registration! Please"
" disconnect and reconnect your Ethernet"
" cable to get Internet access."))
return form(
{},
'users/plugin_out.html',
request
)
return form(
{},
'users/plugin_out.html',
{'userform': u_form, 'action_name': _("Register device or room")},
'users/user.html',
request
)
return form(
{'userform': u_form, 'action_name': _("Register device or room")},
'users/user.html',
request
)
else:
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