wg instance dns settings and peer list refresh interval configuration

This commit is contained in:
Eduardo Silva
2024-02-17 15:03:29 -03:00
parent cfcabed244
commit 3563da423b
10 changed files with 88 additions and 16 deletions

View File

@@ -3,8 +3,8 @@ from .models import WireGuardInstance, Peer, PeerAllowedIP
class WireGuardInstanceAdmin(admin.ModelAdmin):
list_display = ('name', 'instance_id', 'private_key', 'hostname', 'listen_port', 'address', 'netmask', 'post_up', 'post_down', 'persistent_keepalive', 'created', 'updated', 'uuid')
search_fields = ('name', 'instance_id', 'private_key', 'hostname', 'listen_port', 'address', 'netmask', 'post_up', 'post_down', 'persistent_keepalive', 'created', 'updated', 'uuid')
list_display = ('name', 'instance_id', 'private_key', 'hostname', 'listen_port', 'address', 'netmask', 'post_up', 'post_down', 'created', 'updated', 'uuid')
search_fields = ('name', 'instance_id', 'private_key', 'hostname', 'listen_port', 'address', 'netmask', 'post_up', 'post_down', 'created', 'updated', 'uuid')
admin.site.register(WireGuardInstance, WireGuardInstanceAdmin)

View File

@@ -14,12 +14,15 @@ class WireGuardInstanceForm(forms.ModelForm):
netmask = forms.ChoiceField(choices=NETMASK_CHOICES, label='Netmask')
post_up = forms.CharField(label='Post Up', required=False)
post_down = forms.CharField(label='Post Down', required=False)
persistent_keepalive = forms.IntegerField(label='Keepalive')
peer_list_refresh_interval = forms.IntegerField(label='Web Refresh Interval', initial=20)
dns_primary = forms.GenericIPAddressField(label='Primary DNS', initial='1.1.1.1')
dns_secondary = forms.GenericIPAddressField(label='Secondary DNS', initial='1.0.0.1', required=False)
class Meta:
model = WireGuardInstance
fields = [
'name', 'instance_id', 'private_key', 'public_key','hostname', 'listen_port', 'address', 'netmask', 'post_up', 'post_down', 'persistent_keepalive'
'name', 'instance_id', 'private_key', 'public_key','hostname', 'listen_port', 'address',
'netmask', 'post_up', 'post_down', 'peer_list_refresh_interval', 'dns_primary', 'dns_secondary'
]
def clean(self):
@@ -27,6 +30,9 @@ class WireGuardInstanceForm(forms.ModelForm):
hostname = cleaned_data.get('hostname')
address = cleaned_data.get('address')
netmask = cleaned_data.get('netmask')
peer_list_refresh_interval = cleaned_data.get('peer_list_refresh_interval')
if peer_list_refresh_interval < 10:
raise forms.ValidationError('Peer List Refresh Interval must be at least 10 seconds')
if not is_valid_ip_or_hostname(hostname):
raise forms.ValidationError('Invalid hostname or IP Address')

View File

@@ -0,0 +1,17 @@
# Generated by Django 5.0.1 on 2024-02-17 17:21
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('wireguard', '0006_peerstatus'),
]
operations = [
migrations.RemoveField(
model_name='wireguardinstance',
name='persistent_keepalive',
),
]

View File

@@ -0,0 +1,28 @@
# Generated by Django 5.0.1 on 2024-02-17 17:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('wireguard', '0007_remove_wireguardinstance_persistent_keepalive'),
]
operations = [
migrations.AddField(
model_name='wireguardinstance',
name='dns_primary',
field=models.GenericIPAddressField(default='1.1.1.1', protocol='IPv4', unique=True),
),
migrations.AddField(
model_name='wireguardinstance',
name='dns_secondary',
field=models.GenericIPAddressField(blank=True, default='1.0.0.1', null=True, protocol='IPv4', unique=True),
),
migrations.AddField(
model_name='wireguardinstance',
name='peer_list_refresh_interval',
field=models.IntegerField(default=20),
),
]

View File

@@ -40,7 +40,9 @@ class WireGuardInstance(models.Model):
netmask = models.IntegerField(default=24, choices=NETMASK_CHOICES)
post_up = models.TextField(blank=True, null=True)
post_down = models.TextField(blank=True, null=True)
persistent_keepalive = models.IntegerField(default=25)
peer_list_refresh_interval = models.IntegerField(default=20)
dns_primary = models.GenericIPAddressField(unique=True, protocol='IPv4', default='1.1.1.1')
dns_secondary = models.GenericIPAddressField(unique=True, protocol='IPv4', default='1.0.0.1', blank=True, null=True)
pending_changes = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True)