mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-01-25 08:46:17 +00:00
add routing templates model and initial migration
This commit is contained in:
0
routing_templates/__init__.py
Normal file
0
routing_templates/__init__.py
Normal file
1
routing_templates/admin.py
Normal file
1
routing_templates/admin.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# Register your models here.
|
||||||
6
routing_templates/apps.py
Normal file
6
routing_templates/apps.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class RoutingTemplatesConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'routing_templates'
|
||||||
36
routing_templates/migrations/0001_initial.py
Normal file
36
routing_templates/migrations/0001_initial.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Generated by Django 5.2.9 on 2026-01-15 21:22
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('wireguard', '0027_alter_wireguardinstance_peer_list_refresh_interval'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RoutingTemplate',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('default_template', models.BooleanField(default=False)),
|
||||||
|
('name', models.CharField(max_length=32)),
|
||||||
|
('route_type', models.CharField(choices=[('default', 'Default Route (0.0.0.0/0)'), ('peer_same_instance', 'Routes from Peers on same Interface'), ('peer_all_instances', 'Routes from All Peers'), ('custom', 'Custom Routes')], max_length=20)),
|
||||||
|
('custom_routes', models.TextField(blank=True, help_text='One route per line in CIDR notation.', null=True)),
|
||||||
|
('allow_peer_custom_routes', models.BooleanField(default=False)),
|
||||||
|
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
|
||||||
|
('created', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('updated', models.DateTimeField(auto_now=True)),
|
||||||
|
('wireguard_instance', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='wireguard.wireguardinstance')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'unique_together': {('wireguard_instance', 'name')},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
0
routing_templates/migrations/__init__.py
Normal file
0
routing_templates/migrations/__init__.py
Normal file
45
routing_templates/models.py
Normal file
45
routing_templates/models.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
from django.db import models, transaction
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from wireguard.models import WireGuardInstance
|
||||||
|
|
||||||
|
|
||||||
|
class RoutingTemplate(models.Model):
|
||||||
|
ROUTE_TYPE_CHOICES = [
|
||||||
|
("default", _('Default Route (0.0.0.0/0)')),
|
||||||
|
("peer_same_instance", _('Routes from Peers on same Interface')),
|
||||||
|
("peer_all_instances", _('Routes from All Peers')),
|
||||||
|
("custom", _('Custom Routes')),
|
||||||
|
]
|
||||||
|
|
||||||
|
wireguard_instance = models.ForeignKey(WireGuardInstance, on_delete=models.CASCADE)
|
||||||
|
default_template = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
name = models.CharField(max_length=32)
|
||||||
|
route_type = models.CharField(max_length=20, choices=ROUTE_TYPE_CHOICES)
|
||||||
|
|
||||||
|
custom_routes = models.TextField(blank=True, null=True, help_text=_('One route per line in CIDR notation.'))
|
||||||
|
allow_peer_custom_routes = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
||||||
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
updated = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = (("wireguard_instance", "name"),)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
with transaction.atomic():
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
if self.default_template:
|
||||||
|
(
|
||||||
|
RoutingTemplate.objects
|
||||||
|
.filter(wireguard_instance=self.wireguard_instance, default_template=True)
|
||||||
|
.exclude(pk=self.pk)
|
||||||
|
.update(default_template=False)
|
||||||
|
)
|
||||||
1
routing_templates/tests.py
Normal file
1
routing_templates/tests.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# Create your tests here.
|
||||||
1
routing_templates/views.py
Normal file
1
routing_templates/views.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# Create your views here.
|
||||||
@@ -47,7 +47,8 @@ INSTALLED_APPS = [
|
|||||||
'dns',
|
'dns',
|
||||||
'vpn_invite',
|
'vpn_invite',
|
||||||
'cluster',
|
'cluster',
|
||||||
'api'
|
'api',
|
||||||
|
'routing_templates'
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|||||||
Reference in New Issue
Block a user