8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 14:42:25 +00:00

Merge branch 'python2_radius' into 'dev'

Python2 radius

See merge request federez/re2o!250
This commit is contained in:
chirac 2018-08-12 18:30:33 +02:00
commit ee53be34ec
2 changed files with 54 additions and 52 deletions

View file

@ -1005,7 +1005,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
@cached_property @cached_property
def gen_ipv6_dhcpv6(self): def gen_ipv6_dhcpv6(self):
"""Cree une ip, à assigner avec dhcpv6 sur une machine""" """Cree une ip, à assigner avec dhcpv6 sur une machine"""
prefix_v6 = self.type.ip_type.prefix_v6 prefix_v6 = self.type.ip_type.prefix_v6.encode().decode('utf-8')
if not prefix_v6: if not prefix_v6:
return None return None
return IPv6Address( return IPv6Address(
@ -1331,14 +1331,14 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
def check_and_replace_prefix(self, prefix=None): def check_and_replace_prefix(self, prefix=None):
"""Si le prefixe v6 est incorrect, on maj l'ipv6""" """Si le prefixe v6 est incorrect, on maj l'ipv6"""
prefix_v6 = prefix or self.interface.type.ip_type.prefix_v6 prefix_v6 = prefix or self.interface.type.ip_type.prefix_v6.encode().decode('utf-8')
if not prefix_v6: if not prefix_v6:
return return
if (IPv6Address(self.ipv6).exploded[:20] != if (IPv6Address(self.ipv6.encode().decode('utf-8')).exploded[:20] !=
IPv6Address(prefix_v6).exploded[:20]): IPv6Address(prefix_v6).exploded[:20]):
self.ipv6 = IPv6Address( self.ipv6 = IPv6Address(
IPv6Address(prefix_v6).exploded[:20] + IPv6Address(prefix_v6).exploded[:20] +
IPv6Address(self.ipv6).exploded[20:] IPv6Address(self.ipv6.encode().decode('utf-8')).exploded[20:]
) )
self.save() self.save()
@ -1347,9 +1347,9 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
.filter(interface=self.interface, slaac_ip=True) .filter(interface=self.interface, slaac_ip=True)
.exclude(id=self.id)): .exclude(id=self.id)):
raise ValidationError("Une ip slaac est déjà enregistrée") raise ValidationError("Une ip slaac est déjà enregistrée")
prefix_v6 = self.interface.type.ip_type.prefix_v6 prefix_v6 = self.interface.type.ip_type.prefix_v6.encode().decode('utf-8')
if prefix_v6: if prefix_v6:
if (IPv6Address(self.ipv6).exploded[:20] != if (IPv6Address(self.ipv6.encode().decode('utf-8')).exploded[:20] !=
IPv6Address(prefix_v6).exploded[:20]): IPv6Address(prefix_v6).exploded[:20]):
raise ValidationError( raise ValidationError(
"Le prefixv6 est incorrect et ne correspond pas au type " "Le prefixv6 est incorrect et ne correspond pas au type "

View file

@ -48,6 +48,7 @@ from __future__ import unicode_literals
import re import re
import uuid import uuid
import datetime import datetime
import sys
from django.db import models from django.db import models
from django.db.models import Q from django.db.models import Q
@ -67,7 +68,7 @@ from django.contrib.auth.models import (
Group Group
) )
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
import traceback
from reversion import revisions as reversion from reversion import revisions as reversion
import ldapdb.models import ldapdb.models
@ -539,6 +540,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
mac_refresh : synchronise les machines de l'user mac_refresh : synchronise les machines de l'user
group_refresh : synchronise les group de l'user group_refresh : synchronise les group de l'user
Si l'instance n'existe pas, on crée le ldapuser correspondant""" Si l'instance n'existe pas, on crée le ldapuser correspondant"""
if sys.version_info[0] >= 3:
self.refresh_from_db() self.refresh_from_db()
try: try:
user_ldap = LdapUser.objects.get(uidNumber=self.uid_number) user_ldap = LdapUser.objects.get(uidNumber=self.uid_number)
@ -679,7 +681,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
domain.save() domain.save()
self.notif_auto_newmachine(interface_cible) self.notif_auto_newmachine(interface_cible)
except Exception as error: except Exception as error:
return False, error return False, traceback.format_exc()
return interface_cible, "Ok" return interface_cible, "Ok"
def notif_auto_newmachine(self, interface): def notif_auto_newmachine(self, interface):