mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2025-06-27 16:57:01 +00:00
Add pending changes warning context processor
This commit is contained in:
parent
fdc941726c
commit
2b8ec3ac88
@ -1,10 +1,12 @@
|
||||
from wireguard.models import WireGuardInstance
|
||||
from wgwadmlibrary.tools import is_valid_ip_or_hostname
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from user_manager.models import UserAcl
|
||||
import subprocess
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
from user_manager.models import UserAcl
|
||||
from wgwadmlibrary.tools import is_valid_ip_or_hostname
|
||||
from wireguard.models import WireGuardInstance
|
||||
|
||||
|
||||
@login_required
|
||||
def view_console(request):
|
||||
@ -15,10 +17,6 @@ def view_console(request):
|
||||
return render(request, 'access_denied.html', {'page_title': 'Access Denied'})
|
||||
|
||||
wireguard_instances = WireGuardInstance.objects.all().order_by('instance_id')
|
||||
if wireguard_instances.filter(pending_changes=True).exists():
|
||||
pending_changes_warning = True
|
||||
else:
|
||||
pending_changes_warning = False
|
||||
requested_command = request.GET.get('command')
|
||||
command_target = request.GET.get('target', '')
|
||||
if command_target:
|
||||
@ -79,5 +77,5 @@ def view_console(request):
|
||||
command_output = e.output.decode('utf-8')
|
||||
command_success = False
|
||||
|
||||
context = {'page_title': page_title, 'command_output': command_output, 'command_success': command_success, 'pending_changes_warning': pending_changes_warning}
|
||||
context = {'page_title': page_title, 'command_output': command_output, 'command_success': command_success}
|
||||
return render(request, 'console/console.html', context)
|
@ -1,14 +1,14 @@
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.db.models import Max
|
||||
from firewall.models import RedirectRule, FirewallRule, FirewallSettings
|
||||
from firewall.forms import RedirectRuleForm, FirewallRuleForm, FirewallSettingsForm
|
||||
from django.contrib import messages
|
||||
from wireguard.models import WireGuardInstance
|
||||
from user_manager.models import UserAcl
|
||||
from firewall.tools import export_user_firewall, generate_firewall_header, generate_firewall_footer, generate_port_forward_firewall, reset_firewall_to_default
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.utils import timezone
|
||||
from django.db.models import Max
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
|
||||
from firewall.forms import FirewallRuleForm, FirewallSettingsForm, RedirectRuleForm
|
||||
from firewall.models import FirewallRule, FirewallSettings, RedirectRule
|
||||
from firewall.tools import reset_firewall_to_default
|
||||
from user_manager.models import UserAcl
|
||||
from wireguard.models import WireGuardInstance
|
||||
|
||||
|
||||
@login_required
|
||||
@ -16,13 +16,8 @@ def view_redirect_rule_list(request):
|
||||
wireguard_instances = WireGuardInstance.objects.all().order_by('instance_id')
|
||||
if wireguard_instances.filter(legacy_firewall=True).exists():
|
||||
return redirect('/firewall/migration_required/')
|
||||
if wireguard_instances.filter(pending_changes=True).exists():
|
||||
pending_changes_warning = True
|
||||
else:
|
||||
pending_changes_warning = False
|
||||
context = {
|
||||
'page_title': 'Port Forward List',
|
||||
'pending_changes_warning': pending_changes_warning,
|
||||
'redirect_rule_list': RedirectRule.objects.all().order_by('port'),
|
||||
'current_chain': 'portforward',
|
||||
}
|
||||
@ -79,13 +74,8 @@ def view_firewall_rule_list(request):
|
||||
current_chain = request.GET.get('chain', 'forward')
|
||||
if current_chain not in ['forward', 'portforward', 'postrouting']:
|
||||
current_chain = 'forward'
|
||||
if wireguard_instances.filter(pending_changes=True).exists():
|
||||
pending_changes_warning = True
|
||||
else:
|
||||
pending_changes_warning = False
|
||||
context = {
|
||||
'page_title': 'Firewall Rule List',
|
||||
'pending_changes_warning': pending_changes_warning,
|
||||
'firewall_rule_list': FirewallRule.objects.filter(firewall_chain=current_chain).order_by('sort_order'),
|
||||
'current_chain': current_chain,
|
||||
'port_forward_list': RedirectRule.objects.all().order_by('port'),
|
||||
|
9
wireguard/context_processors.py
Normal file
9
wireguard/context_processors.py
Normal file
@ -0,0 +1,9 @@
|
||||
from .models import WireGuardInstance
|
||||
|
||||
|
||||
def pending_changes_warning(request):
|
||||
if request.user.is_authenticated:
|
||||
pending = WireGuardInstance.objects.filter(pending_changes=True).exists()
|
||||
else:
|
||||
pending = False
|
||||
return {'pending_changes_warning': pending}
|
@ -1,16 +1,14 @@
|
||||
from decimal import Decimal, ROUND_DOWN
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from user_manager.models import UserAcl
|
||||
|
||||
from wireguard.forms import WireGuardInstanceForm
|
||||
from .models import WireGuardInstance, WebadminSettings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib import messages
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db import models
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
|
||||
from user_manager.models import UserAcl
|
||||
from wireguard.forms import WireGuardInstanceForm
|
||||
from .models import WebadminSettings, WireGuardInstance
|
||||
|
||||
|
||||
def generate_instance_defaults():
|
||||
max_instance_id = WireGuardInstance.objects.all().aggregate(models.Max('instance_id'))['instance_id__max']
|
||||
@ -74,10 +72,6 @@ def legacy_view_wireguard_status(request):
|
||||
user_acl = get_object_or_404(UserAcl, user=request.user)
|
||||
page_title = 'WireGuard Status'
|
||||
wireguard_instances = WireGuardInstance.objects.all().order_by('instance_id')
|
||||
if wireguard_instances.filter(pending_changes=True).exists():
|
||||
pending_changes_warning = True
|
||||
else:
|
||||
pending_changes_warning = False
|
||||
|
||||
if user_acl.enable_enhanced_filter:
|
||||
command_output = 'Enhanced filter is enabled. This command is not available.'
|
||||
@ -91,7 +85,7 @@ def legacy_view_wireguard_status(request):
|
||||
command_output = e.output.decode('utf-8')
|
||||
command_success = False
|
||||
|
||||
context = {'page_title': page_title, 'command_output': command_output, 'command_success': command_success, 'pending_changes_warning': pending_changes_warning, 'wireguard_instances': wireguard_instances}
|
||||
context = {'page_title': page_title, 'command_output': command_output, 'command_success': command_success, 'wireguard_instances': wireguard_instances}
|
||||
return render(request, 'wireguard/wireguard_status.html', context)
|
||||
|
||||
|
||||
@ -109,15 +103,10 @@ def view_wireguard_status(request):
|
||||
else:
|
||||
wireguard_instances = WireGuardInstance.objects.all().order_by('instance_id')
|
||||
|
||||
if WireGuardInstance.objects.filter(pending_changes=True).exists():
|
||||
pending_changes_warning = True
|
||||
else:
|
||||
pending_changes_warning = False
|
||||
|
||||
if user_acl.enable_enhanced_filter:
|
||||
pass
|
||||
|
||||
context = {'page_title': page_title, 'pending_changes_warning': pending_changes_warning, 'wireguard_instances': wireguard_instances}
|
||||
context = {'page_title': page_title, 'wireguard_instances': wireguard_instances}
|
||||
return render(request, 'wireguard/wireguard_status.html', context)
|
||||
|
||||
|
||||
@ -126,10 +115,6 @@ def view_wireguard_manage_instance(request):
|
||||
if not UserAcl.objects.filter(user=request.user).filter(user_level__gte=50).exists():
|
||||
return render(request, 'access_denied.html', {'page_title': 'Access Denied'})
|
||||
wireguard_instances = WireGuardInstance.objects.all().order_by('instance_id')
|
||||
if wireguard_instances.filter(pending_changes=True).exists():
|
||||
pending_changes_warning = True
|
||||
else:
|
||||
pending_changes_warning = False
|
||||
if request.GET.get('uuid'):
|
||||
current_instance = get_object_or_404(WireGuardInstance, uuid=request.GET.get('uuid'))
|
||||
else:
|
||||
@ -172,7 +157,7 @@ def view_wireguard_manage_instance(request):
|
||||
form = WireGuardInstanceForm(initial=generate_instance_defaults())
|
||||
else:
|
||||
form = WireGuardInstanceForm(instance=current_instance)
|
||||
context = {'page_title': page_title, 'wireguard_instances': wireguard_instances, 'current_instance': current_instance, 'form': form, 'pending_changes_warning': pending_changes_warning}
|
||||
context = {'page_title': page_title, 'wireguard_instances': wireguard_instances, 'current_instance': current_instance, 'form': form}
|
||||
return render(request, 'wireguard/wireguard_manage_server.html', context)
|
||||
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from user_manager.models import UserAcl
|
||||
from wireguard.models import WireGuardInstance, Peer, PeerAllowedIP
|
||||
from django.contrib import messages
|
||||
from django.db.models import Max
|
||||
import subprocess
|
||||
import ipaddress
|
||||
from wgwadmlibrary.tools import user_has_access_to_peer, user_has_access_to_instance, user_allowed_instances, user_allowed_peers, default_sort_peers, deduplicate_sort_order, check_sort_order_conflict
|
||||
import subprocess
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import Http404
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
|
||||
from user_manager.models import UserAcl
|
||||
from wgwadmlibrary.tools import check_sort_order_conflict, deduplicate_sort_order, default_sort_peers, \
|
||||
user_allowed_instances, user_allowed_peers, user_has_access_to_instance, user_has_access_to_peer
|
||||
from wireguard.models import Peer, PeerAllowedIP, WireGuardInstance
|
||||
from wireguard_peer.forms import PeerAllowedIPForm, PeerForm
|
||||
|
||||
|
||||
@ -47,11 +49,6 @@ def view_wireguard_peer_list(request):
|
||||
page_title = 'WireGuard Peer List'
|
||||
user_acl = get_object_or_404(UserAcl, user=request.user)
|
||||
wireguard_instances = user_allowed_instances(user_acl)
|
||||
|
||||
if WireGuardInstance.objects.filter(pending_changes=True).exists():
|
||||
pending_changes_warning = True
|
||||
else:
|
||||
pending_changes_warning = False
|
||||
|
||||
if wireguard_instances:
|
||||
if request.GET.get('uuid'):
|
||||
@ -71,7 +68,7 @@ def view_wireguard_peer_list(request):
|
||||
if user_has_access_to_instance(user_acl, current_instance):
|
||||
add_peer_enabled = True
|
||||
|
||||
context = {'page_title': page_title, 'wireguard_instances': wireguard_instances, 'current_instance': current_instance, 'peer_list': peer_list, 'pending_changes_warning': pending_changes_warning, 'add_peer_enabled': add_peer_enabled, 'user_acl': user_acl}
|
||||
context = {'page_title': page_title, 'wireguard_instances': wireguard_instances, 'current_instance': current_instance, 'peer_list': peer_list, 'add_peer_enabled': add_peer_enabled, 'user_acl': user_acl}
|
||||
return render(request, 'wireguard/wireguard_peer_list.html', context)
|
||||
|
||||
|
||||
|
@ -71,6 +71,7 @@ TEMPLATES = [
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'wireguard.context_processors.pending_changes_warning',
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -135,6 +136,6 @@ STATICFILES_DIRS = [
|
||||
DNS_CONFIG_FILE = '/etc/dnsmasq/wireguard_webadmin_dns.conf'
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
WIREGUARD_WEBADMIN_VERSION = 9962
|
||||
WIREGUARD_WEBADMIN_VERSION = 9963
|
||||
|
||||
from wireguard_webadmin.production_settings import *
|
||||
|
Loading…
x
Reference in New Issue
Block a user