mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2025-04-19 08:55:12 +00:00
Pending configuration warning and reload
This commit is contained in:
parent
d5edc5bb2e
commit
0a14192444
@ -1,3 +1,4 @@
|
||||
from wireguard.models import WireGuardInstance
|
||||
from wgwadmlibrary.tools import is_valid_ip_or_hostname
|
||||
from django.shortcuts import render
|
||||
from django.contrib.auth.decorators import login_required
|
||||
@ -7,6 +8,11 @@ import subprocess
|
||||
@login_required
|
||||
def view_console(request):
|
||||
page_title = 'Console'
|
||||
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:
|
||||
@ -59,5 +65,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}
|
||||
context = {'page_title': page_title, 'command_output': command_output, 'command_success': command_success, 'pending_changes_warning': pending_changes_warning}
|
||||
return render(request, 'console/console.html', context)
|
@ -168,6 +168,19 @@
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
{% if pending_changes_warning %}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<h4 class="alert-heading">Update Required</h4>
|
||||
<p>Your WireGuard settings have been modified. To apply these changes, please update the configuration and reload the WireGuard service.
|
||||
</p>
|
||||
<p>
|
||||
<a href="/tools/export_wireguard_config/?action=update_and_restart" class="btn btn-secondary">Update and restart service</a>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
|
||||
{% block content %}{% endblock %}
|
||||
@ -179,7 +192,7 @@
|
||||
<footer class="main-footer">
|
||||
wireguard-webadmin
|
||||
<div class="float-right d-none d-sm-inline-block">
|
||||
<b>Version</b> 0.8 beta
|
||||
<b>Version</b> 0.8.1 beta
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
@ -5,17 +5,15 @@
|
||||
<p>I've been working hard on it over the past week and plan to continue making corrections and finishing it in the coming days.</p>
|
||||
<p>Currently, it's quite functional, but there's still a need to polish various aspects of the interface to enhance usability.</p>
|
||||
<p>If you encounter any issues or have suggestions, please open an issue on GitHub so I can review it.</p>
|
||||
<h2>Important Points to Note:</h2>
|
||||
<h2>TODO list</h2>
|
||||
<ul>
|
||||
<li>The peers page does not yet display data from WireGuard such as the last handshake and data transfer.</li>
|
||||
<li>The verification of allowed IPs against the output of wg show has not yet been implemented. This will help detect configuration errors for crypto routing.</li>
|
||||
<li>After editing a peer or server settings, go to the status page and click to update the WireGuard configurations, then restart the service. I still need to make this process more intuitive.</li>
|
||||
<li>The DNS server provided to the peer is still hardcoded.</li>
|
||||
<li>AllowedIPs on client configuration side.</li>
|
||||
</ul>
|
||||
<p>Your involvement and feedback are crucial to the development of wireguard_webadmin. Together, we can refine and enhance its functionality. Thank you for being part of this journey!</p>
|
||||
|
||||
|
||||
<h2>Don't Forget</h2>
|
||||
<p>Remember to save your configuration changes and restart the service for them to take effect.</p>
|
||||
<p>Keep checking the GitHub page, I will be updating this project very soon.</p>
|
||||
|
||||
{% endblock %}
|
||||
|
28
wireguard/migrations/0006_peerstatus.py
Normal file
28
wireguard/migrations/0006_peerstatus.py
Normal file
@ -0,0 +1,28 @@
|
||||
# Generated by Django 5.0.1 on 2024-02-16 19:01
|
||||
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wireguard', '0005_wireguardinstance_pending_changes'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='PeerStatus',
|
||||
fields=[
|
||||
('last_handshake', models.DateTimeField(blank=True, null=True)),
|
||||
('transfer_rx', models.BigIntegerField(default=0)),
|
||||
('transfer_tx', models.BigIntegerField(default=0)),
|
||||
('latest_config', models.TextField(blank=True, null=True)),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('updated', models.DateTimeField(auto_now=True)),
|
||||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('peer', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='wireguard.peer')),
|
||||
],
|
||||
),
|
||||
]
|
@ -73,6 +73,21 @@ class Peer(models.Model):
|
||||
return self.public_key
|
||||
|
||||
|
||||
class PeerStatus(models.Model):
|
||||
peer = models.OneToOneField(Peer, on_delete=models.CASCADE)
|
||||
last_handshake = models.DateTimeField(blank=True, null=True)
|
||||
transfer_rx = models.BigIntegerField(default=0)
|
||||
transfer_tx = models.BigIntegerField(default=0)
|
||||
latest_config = models.TextField(blank=True, null=True)
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
updated = models.DateTimeField(auto_now=True)
|
||||
uuid = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.peer)
|
||||
|
||||
|
||||
class PeerAllowedIP(models.Model):
|
||||
peer = models.ForeignKey(Peer, on_delete=models.CASCADE)
|
||||
priority = models.PositiveBigIntegerField(default=1)
|
||||
|
@ -75,6 +75,11 @@ def view_welcome(request):
|
||||
@login_required
|
||||
def view_wireguard_status(request):
|
||||
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
|
||||
bash_command = ['bash', '-c', 'wg show']
|
||||
try:
|
||||
command_output = subprocess.check_output(bash_command, stderr=subprocess.STDOUT).decode('utf-8')
|
||||
@ -83,7 +88,7 @@ def 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}
|
||||
context = {'page_title': page_title, 'command_output': command_output, 'command_success': command_success, 'pending_changes_warning': pending_changes_warning, 'wireguard_instances': wireguard_instances}
|
||||
return render(request, 'wireguard/wireguard_status.html', context)
|
||||
|
||||
|
||||
@ -92,6 +97,10 @@ 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:
|
||||
@ -124,7 +133,9 @@ def view_wireguard_manage_instance(request):
|
||||
if request.method == 'POST':
|
||||
form = WireGuardInstanceForm(request.POST, instance=current_instance)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
this_form = form.save(commit=False)
|
||||
this_form.pending_changes = True
|
||||
this_form.save()
|
||||
messages.success(request, message_title + '|WireGuard instance wg' + str(form.instance.instance_id) + ' saved successfully.')
|
||||
return redirect('/server/manage/?uuid=' + str(form.instance.uuid))
|
||||
else:
|
||||
@ -132,5 +143,5 @@ 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}
|
||||
context = {'page_title': page_title, 'wireguard_instances': wireguard_instances, 'current_instance': current_instance, 'form': form, 'pending_changes_warning': pending_changes_warning}
|
||||
return render(request, 'wireguard/wireguard_manage_server.html', context)
|
@ -45,6 +45,10 @@ def generate_peer_default(wireguard_instance):
|
||||
def view_wireguard_peer_list(request):
|
||||
page_title = 'WireGuard Peer List'
|
||||
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 wireguard_instances:
|
||||
if request.GET.get('uuid'):
|
||||
current_instance = get_object_or_404(WireGuardInstance, uuid=request.GET.get('uuid'))
|
||||
@ -55,7 +59,7 @@ def view_wireguard_peer_list(request):
|
||||
current_instance = None
|
||||
peer_list = None
|
||||
|
||||
context = {'page_title': page_title, 'wireguard_instances': wireguard_instances, 'current_instance': current_instance, 'peer_list': peer_list}
|
||||
context = {'page_title': page_title, 'wireguard_instances': wireguard_instances, 'current_instance': current_instance, 'peer_list': peer_list, 'pending_changes_warning': pending_changes_warning}
|
||||
return render(request, 'wireguard/wireguard_peer_list.html', context)
|
||||
|
||||
|
||||
@ -90,6 +94,8 @@ def view_wireguard_peer_manage(request):
|
||||
netmask=32,
|
||||
)
|
||||
messages.success(request, 'Peer created|Peer for instance wg' + str(current_instance.instance_id) + ' created successfully with IP ' + new_peer_data['allowed_ip'] + '/32.')
|
||||
new_peer.wireguard_instance.pending_changes = True
|
||||
new_peer.wireguard_instance.save()
|
||||
return redirect('/peer/manage/?peer=' + str(new_peer.uuid))
|
||||
else:
|
||||
messages.warning(request, 'Error creating peer|No available IP address found for peer creation.')
|
||||
@ -100,6 +106,8 @@ def view_wireguard_peer_manage(request):
|
||||
current_instance = current_peer.wireguard_instance
|
||||
if request.GET.get('action') == 'delete':
|
||||
if request.GET.get('confirmation') == 'delete':
|
||||
current_peer.wireguard_instance.pending_changes = True
|
||||
current_peer.wireguard_instance.save()
|
||||
current_peer.delete()
|
||||
messages.success(request, 'Peer deleted|Peer deleted successfully.')
|
||||
return redirect('/peer/list/?uuid=' + str(current_instance.uuid))
|
||||
@ -117,6 +125,8 @@ def view_wireguard_peer_manage(request):
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, 'Peer updated|Peer updated successfully.')
|
||||
current_peer.wireguard_instance.pending_changes = True
|
||||
current_peer.wireguard_instance.save()
|
||||
return redirect('/peer/list/?uuid=' + str(current_peer.wireguard_instance.uuid))
|
||||
else:
|
||||
form = PeerForm(instance=current_peer)
|
||||
@ -152,6 +162,8 @@ def view_manage_ip_address(request):
|
||||
if request.GET.get('confirmation') == 'delete':
|
||||
current_ip.delete()
|
||||
messages.success(request, 'IP address deleted|IP address deleted successfully.')
|
||||
current_peer.wireguard_instance.pending_changes = True
|
||||
current_peer.wireguard_instance.save()
|
||||
return redirect('/peer/manage/?peer=' + str(current_peer.uuid))
|
||||
else:
|
||||
messages.warning(request, 'Error deleting IP address|Invalid confirmation message. Type "delete" to confirm.')
|
||||
@ -164,7 +176,8 @@ def view_manage_ip_address(request):
|
||||
if not current_ip:
|
||||
this_form.peer = current_peer
|
||||
this_form.save()
|
||||
form.save()
|
||||
current_peer.wireguard_instance.pending_changes = True
|
||||
current_peer.wireguard_instance.save()
|
||||
if current_ip:
|
||||
messages.success(request, 'IP address updated|IP address updated successfully.')
|
||||
else:
|
||||
|
@ -88,6 +88,8 @@ def export_wireguard_configs(request):
|
||||
with open(config_path, "w") as config_file:
|
||||
config_file.write(config_content)
|
||||
messages.success(request, "Export successful!|WireGuard configuration files have been exported to /etc/wireguard/. Don't forget to restart the interfaces.")
|
||||
if request.GET.get('action') == 'update_and_restart':
|
||||
return redirect('/tools/restart_wireguard/?action=dismiss_warning')
|
||||
return redirect('/status/')
|
||||
|
||||
|
||||
@ -159,6 +161,9 @@ def restart_wireguard_interfaces(request):
|
||||
|
||||
if interface_count == 0 and error_count == 0:
|
||||
messages.info(request, "No interfaces found|No WireGuard interfaces were found to restart.")
|
||||
|
||||
if request.GET.get('action') == 'dismiss_warning':
|
||||
for wireguard_instancee in WireGuardInstance.objects.filter(pending_changes=True):
|
||||
wireguard_instancee.pending_changes = False
|
||||
wireguard_instancee.save()
|
||||
return redirect("/status/")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user