Add flush cache command to console

This commit is contained in:
Eduardo Silva
2026-02-03 18:53:06 -03:00
parent 2945be9ffa
commit 08c4d0079e
2 changed files with 37 additions and 18 deletions

View File

@@ -4,6 +4,8 @@ from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from api.models import WireguardStatusCache
from cluster.models import WorkerStatus
from user_manager.models import UserAcl from user_manager.models import UserAcl
from wgwadmlibrary.tools import is_valid_ip_or_hostname from wgwadmlibrary.tools import is_valid_ip_or_hostname
from wireguard.models import WireGuardInstance from wireguard.models import WireGuardInstance
@@ -34,6 +36,11 @@ def view_console(request):
bash_command = ['bash', '-c', 'ps faux'] bash_command = ['bash', '-c', 'ps faux']
elif requested_command == 'wgshow': elif requested_command == 'wgshow':
page_title += _('WireGuard show') page_title += _('WireGuard show')
if user_acl.enable_enhanced_filter:
command_output = _('Enhanced filter is enabled. This command is not available.')
bash_command = None
command_success = False
else:
bash_command = ['bash', '-c', 'wg show'] bash_command = ['bash', '-c', 'wg show']
elif requested_command == 'freem': elif requested_command == 'freem':
page_title += _('Memory usage') page_title += _('Memory usage')
@@ -53,23 +60,34 @@ def view_console(request):
elif requested_command == 'testdns': elif requested_command == 'testdns':
page_title += _('DNS container test script') page_title += _('DNS container test script')
bash_command = ['/app/dns/scripts/test_dns_service.sh'] bash_command = ['/app/dns/scripts/test_dns_service.sh']
elif requested_command == 'flush_cache':
page_title += _('Flush Wireguard status cache')
bash_command = ''
else: else:
page_title = _('Console') + ': ' + _('Invalid command') page_title = _('Console') + ': ' + _('Invalid command')
bash_command = None bash_command = None
command_output = '' command_output = ''
command_success = False command_success = False
if requested_command == 'ping' or requested_command == 'traceroute': if requested_command == 'flush_cache':
if not command_target: command_output = ''
for worker_status in WorkerStatus.objects.all():
worker_status.wireguard_status = ''
worker_status.wireguard_status_updated = None
worker_status.save()
command_output += _('Flushed WireGuard status cache for worker: ') + str(worker_status.worker) + '\n'
command_success = True
wireguard_status_cache_count = WireGuardInstance.objects.all().count()
WireguardStatusCache.objects.all().delete()
command_output += _('Flushed WireGuard status cache entries: ') + str(wireguard_status_cache_count) + '\n'
command_success = True
if requested_command in ['ping', 'traceroute'] and not command_target:
command_output = requested_command + ': ' + _('Invalid target') command_output = requested_command + ': ' + _('Invalid target')
bash_command = None bash_command = None
command_success = False command_success = False
if user_acl.enable_enhanced_filter and requested_command == 'wgshow':
command_output = _('Enhanced filter is enabled. This command is not available.')
bash_command = None
command_success = False
else:
if bash_command: if bash_command:
try: try:
command_output = subprocess.check_output(bash_command, stderr=subprocess.STDOUT).decode('utf-8') command_output = subprocess.check_output(bash_command, stderr=subprocess.STDOUT).decode('utf-8')

View File

@@ -20,6 +20,7 @@
<a href='javascript:void(0)' class='btn btn-outline-primary' data-command='traceroute' onclick='openCommandDialog(this)'>traceroute</a> <a href='javascript:void(0)' class='btn btn-outline-primary' data-command='traceroute' onclick='openCommandDialog(this)'>traceroute</a>
<a href='javascript:void(0)' class='btn btn-outline-primary' data-command='ping' onclick='openCommandDialog(this)'>ping</a> <a href='javascript:void(0)' class='btn btn-outline-primary' data-command='ping' onclick='openCommandDialog(this)'>ping</a>
<a href='?command=testdns' class='btn btn-outline-primary'>dns test</a> <a href='?command=testdns' class='btn btn-outline-primary'>dns test</a>
<a href='?command=flush_cache' class='btn btn-outline-primary'>flush cache</a>
<script> <script>
function openCommandDialog(element) { function openCommandDialog(element) {