Files

46 lines
1.4 KiB
Python
Raw Permalink Normal View History

2025-08-27 09:55:55 +02:00
import json
import logging
from django.contrib import messages
from django.db.transaction import atomic
from django.forms import model_to_dict
from django.shortcuts import HttpResponse, redirect
from django_auth_ldap.backend import LDAPBackend
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.views.decorators.http import require_http_methods
from django_proxmox_mikrotik.configs import MikrotikConfig
from lib.decorators import force_write
from manager.models import CloneContainer
@atomic
@force_write
def test_mikrotik(request):
from mikrotik.models import DNSStatic
dns = DNSStatic.objects.create(name='test.test1', address='192.168.1.254')
logging.debug(model_to_dict(dns))
response = dns.sync_to_router()
return HttpResponse(json.dumps([model_to_dict(dns), response], indent=4, default=lambda x: str(x)),
content_type="application/json")
def sync_all(request):
"""TODO - just get the user and check on superuser
settings via groups does not work at the moment"""
from manager.admin import resync_all
backend = LDAPBackend()
user = backend.authenticate(request, request.user.username, request.POST.get('password'))
if user and user.is_superuser:
resync_all()
messages.success(request, 'Sync all initiated')
else:
messages.error(request, 'Not authorized')
return redirect('frontend:dashboard')