8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-22 23:13:46 +00:00

Fix bug in prod

This commit is contained in:
chapeau 2024-04-24 19:12:56 +02:00
parent 4df043d730
commit 609f1cfaef
2 changed files with 13 additions and 10 deletions

View file

@ -22,6 +22,7 @@
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from rest_framework.response import Response from rest_framework.response import Response
from django.db.models import Q from django.db.models import Q
from django.db import DataError
from django.http import HttpResponse from django.http import HttpResponse
from django.forms import ValidationError from django.forms import ValidationError
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
@ -61,9 +62,11 @@ def authorize(request, nas_id, username):
""" """
# get the Nas object which made the request (if exists) # get the Nas object which made the request (if exists)
nas_interface = Interface.objects.filter( try:
Q(domain__name=nas_id) | Q(ipv4__ipv4=nas_id) nas_interface = Interface.objects.filter(Q(ipv4__ipv4=nas_id)).first()
).first() except DataError:
nas_interface = Interface.objects.filter(Q(domain__name=nas_id)).first()
nas_type = None nas_type = None
if nas_interface: if nas_interface:
nas_type = Nas.objects.filter(nas_type=nas_interface.machine_type).first() nas_type = Nas.objects.filter(nas_type=nas_interface.machine_type).first()
@ -130,11 +133,11 @@ def post_auth(request, nas_id, nas_port, user_mac, username):
""" """
# get the Nas object which made the request (if exists) # get the Nas object which made the request (if exists)
nas_interface = ( try:
Interface.objects.prefetch_related("machine__switch__stack") nas_interface = Interface.objects.prefetch_related("machine__switch__stack").filter(Q(ipv4__ipv4=nas_id)).first()
.filter(Q(domain__name=nas_id) | Q(ipv4__ipv4=nas_id)) except DataError:
.first() nas_interface = Interface.objects.prefetch_related("machine__switch__stack").filter(Q(domain__name=nas_id)).first()
)
nas_type = None nas_type = None
if nas_interface: if nas_interface:
nas_type = Nas.objects.filter(nas_type=nas_interface.machine_type).first() nas_type = Nas.objects.filter(nas_type=nas_interface.machine_type).first()

View file

@ -49,7 +49,7 @@ def genstring(length=16, chars=string.printable):
def encrypt(key, secret): def encrypt(key, secret):
""" AES Encrypt a secret with the key `key` """ """ AES Encrypt a secret with the key `key` """
obj = AES.new(key) obj = AES.new(key, AES.MODE_ECB)
datalength = len(secret) + len(EOD) datalength = len(secret) + len(EOD)
if datalength < 16: if datalength < 16:
saltlength = 16 - datalength saltlength = 16 - datalength
@ -61,7 +61,7 @@ def encrypt(key, secret):
def decrypt(key, secret): def decrypt(key, secret):
""" AES Decrypt a secret with the key `key` """ """ AES Decrypt a secret with the key `key` """
obj = AES.new(key) obj = AES.new(key, AES.MODE_ECB)
uncrypted_secret = obj.decrypt(secret) uncrypted_secret = obj.decrypt(secret)
return uncrypted_secret.split(EOD_asbyte)[0] return uncrypted_secret.split(EOD_asbyte)[0]