mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-02-19 19:26:17 +00:00
Add filtering for disabled WireGuard peers in peer list view
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
{% for wgconf in wireguard_instances %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if wgconf == current_instance %}active{% endif %}"
|
||||
href="/peer/list/?uuid={{ wgconf.uuid }}" role="tab">
|
||||
href="{% url 'wireguard_peer_list' %}?uuid={{ wgconf.uuid }}" role="tab">
|
||||
wg{{ wgconf.instance_id }} {% if wgconf.name %}({{ wgconf.name }}){% endif %}
|
||||
</a>
|
||||
</li>
|
||||
@@ -37,6 +37,17 @@
|
||||
<a class="btn btn-primary disabled" href="">{% trans 'Create Peer' %}</a>
|
||||
{% endif %}
|
||||
<button id="toggleExtraInfo" class="btn btn-outline-primary">{% trans 'Show extras' %}</button>
|
||||
{% if show_only_disabled_peers %}
|
||||
<a class="btn btn-outline-secondary"
|
||||
href="{% url 'wireguard_peer_list' %}?uuid={{ current_instance.uuid }}">
|
||||
{% trans 'Enabled' %}
|
||||
</a>
|
||||
{% else %}
|
||||
<a class="btn btn-outline-secondary"
|
||||
href="{% url 'wireguard_peer_list' %}?uuid={{ current_instance.uuid }}&peer_status=disabled">
|
||||
{% trans 'Disabled' %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -63,7 +74,9 @@
|
||||
|
||||
{% include 'wireguard/peer_list/script_peer_charts_init.html' %}
|
||||
{% include 'wireguard/peer_list/script_peer_modal.html' %}
|
||||
{% include 'wireguard/peer_list/script_wireguard_status_update.html' %}
|
||||
{% if not show_only_disabled_peers %}
|
||||
{% include 'wireguard/peer_list/script_wireguard_status_update.html' %}
|
||||
{% endif %}
|
||||
{% include 'wireguard/peer_list/script_peer_extras_toggle.html' %}
|
||||
{% include 'wireguard/peer_list/script_vpn_invite.html' %}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import subprocess
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Q
|
||||
from django.http import Http404
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@@ -50,9 +51,15 @@ def generate_peer_default(wireguard_instance):
|
||||
|
||||
@login_required
|
||||
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 request.GET.get('peer_status', '') == 'disabled':
|
||||
page_title = _('Disabled WireGuard Peer List')
|
||||
show_only_disabled_peers = True
|
||||
else:
|
||||
page_title = _('WireGuard Peer List')
|
||||
show_only_disabled_peers = False
|
||||
|
||||
refresh_interval = 120
|
||||
if settings.WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT > 0 and settings.WIREGUARD_STATUS_CACHE_ENABLED:
|
||||
load_from_cache = True
|
||||
@@ -78,6 +85,10 @@ def view_wireguard_peer_list(request):
|
||||
raise Http404
|
||||
default_sort_peers(current_instance)
|
||||
peer_list = user_allowed_peers(user_acl, current_instance)
|
||||
if show_only_disabled_peers:
|
||||
peer_list = peer_list.filter(Q(disabled_by_schedule=True) | Q(suspended=True))
|
||||
else:
|
||||
peer_list = peer_list.filter(disabled_by_schedule=False, suspended=False)
|
||||
else:
|
||||
current_instance = None
|
||||
peer_list = None
|
||||
@@ -109,6 +120,7 @@ def view_wireguard_peer_list(request):
|
||||
'load_from_cache': load_from_cache, 'cache_previous_count': cache_previous_count,
|
||||
'cluster_settings': cluster_settings,
|
||||
'servers': servers,
|
||||
'show_only_disabled_peers': show_only_disabled_peers,
|
||||
}
|
||||
|
||||
return render(request, 'wireguard/wireguard_peer_list.html', context)
|
||||
|
||||
Reference in New Issue
Block a user