mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
Specify range for autocapture
This commit is contained in:
parent
cd8a23da31
commit
623be9ac83
5 changed files with 63 additions and 20 deletions
|
@ -397,7 +397,10 @@ class IpType(RevMixin, AclMixin, models.Model):
|
|||
@cached_property
|
||||
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)
|
||||
else:
|
||||
return None
|
||||
|
||||
def ip_objects(self):
|
||||
""" Renvoie tous les objets ipv4 relié à ce type"""
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# -*- 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,6 +1087,8 @@ def process_passwd(request, req):
|
|||
|
||||
@login_required
|
||||
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):
|
|||
'users/user.html',
|
||||
request
|
||||
)
|
||||
else:
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
class JSONResponse(HttpResponse):
|
||||
|
|
Loading…
Reference in a new issue