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): ...@@ -397,7 +397,10 @@ class IpType(RevMixin, AclMixin, models.Model):
@cached_property @cached_property
def complete_prefixv6(self): def complete_prefixv6(self):
"""Return the complete prefix v6 as cidr""" """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): def ip_objects(self):
""" Renvoie tous les objets ipv4 relié à ce type""" """ 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): ...@@ -149,6 +149,13 @@ class OptionalMachine(AclMixin, PreferencesModel):
default=True 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 @cached_property
def ipv6(self): def ipv6(self):
""" Check if the IPv6 option is activated """ """ Check if the IPv6 option is activated """
......
...@@ -96,6 +96,11 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -96,6 +96,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr> <tr>
<th>{% trans "Creation of machines" %}</th> <th>{% trans "Creation of machines" %}</th>
<td>{{ machineoptions.create_machine|tick }}</td> <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> </tr>
</table> </table>
<h4>{% trans "Topology preferences" %}</h4> <h4>{% trans "Topology preferences" %}</h4>
......
...@@ -47,13 +47,14 @@ from django.http import HttpResponse ...@@ -47,13 +47,14 @@ from django.http import HttpResponse
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.core.exceptions import PermissionDenied
from rest_framework.renderers import JSONRenderer from rest_framework.renderers import JSONRenderer
from reversion import revisions as reversion from reversion import revisions as reversion
from cotisations.models import Facture, Paiement from cotisations.models import Facture, Paiement
from machines.models import Machine 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.views import form
from re2o.utils import ( from re2o.utils import (
all_has_access, all_has_access,
...@@ -71,6 +72,8 @@ from re2o.acl import ( ...@@ -71,6 +72,8 @@ from re2o.acl import (
) )
from cotisations.utils import find_payment_method from cotisations.utils import find_payment_method
from netaddr import IPAddress, IPNetwork
from .serializers import MailingSerializer, MailingMemberSerializer from .serializers import MailingSerializer, MailingMemberSerializer
from .models import ( from .models import (
User, User,
...@@ -1084,27 +1087,31 @@ def process_passwd(request, req): ...@@ -1084,27 +1087,31 @@ def process_passwd(request, req):
@login_required @login_required
def initial_register(request): 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)) options, created = OptionalMachine.objects.get_or_create()
if not u_form.fields: 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 ):
messages.error(request, _("Incorrect URL, or already registered device")) 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))
return redirect(reverse( if not u_form.fields:
'users:profil', messages.error(request, _("Incorrect URL, or already registered device"))
kwargs={'userid': str(request.user.id)} return redirect(reverse(
)) 'users:profil',
if u_form.is_valid(): kwargs={'userid': str(request.user.id)}
messages.success(request, _("Successful registration! Please" ))
" disconnect and reconnect your Ethernet" if u_form.is_valid():
" cable to get Internet access.")) 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( return form(
{}, {'userform': u_form, 'action_name': _("Register device or room")},
'users/plugin_out.html', 'users/user.html',
request request
) )
return form( else:
{'userform': u_form, 'action_name': _("Register device or room")}, raise PermissionDenied
'users/user.html',
request
)
class JSONResponse(HttpResponse): 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