mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Merge branch '212-feature-request-allow-to-define-ttl-for-dns-records' into 'dev'
Fix #212 See merge request federez/re2o!453
This commit is contained in:
commit
2c815ab98c
13 changed files with 155 additions and 12 deletions
|
@ -135,16 +135,16 @@ class AddInterfaceForm(EditInterfaceForm):
|
|||
fields = ['machine_type', 'ipv4', 'mac_address', 'details']
|
||||
|
||||
|
||||
class AliasForm(FormRevMixin, ModelForm):
|
||||
class AliasForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||
"""Ajout d'un alias (et edition), CNAME, contenant nom et extension"""
|
||||
|
||||
class Meta:
|
||||
model = Domain
|
||||
fields = ['name', 'extension']
|
||||
fields = ['name', 'extension', 'ttl']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||
user = kwargs.pop('user')
|
||||
user = kwargs['user']
|
||||
super(AliasForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||
can_use_all, _reason, _permissions = Extension.can_use_all(user)
|
||||
if not can_use_all:
|
||||
|
@ -153,16 +153,16 @@ class AliasForm(FormRevMixin, ModelForm):
|
|||
)
|
||||
|
||||
|
||||
class DomainForm(FormRevMixin, ModelForm):
|
||||
class DomainForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||
"""Ajout et edition d'un enregistrement de nom, relié à interface"""
|
||||
|
||||
class Meta:
|
||||
model = Domain
|
||||
fields = ['name']
|
||||
fields = ['name', 'ttl']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if 'user' in kwargs:
|
||||
user = kwargs.pop('user')
|
||||
user = kwargs['user']
|
||||
initial = kwargs.get('initial', {})
|
||||
initial['name'] = user.get_next_domain_name()
|
||||
kwargs['initial'] = initial
|
||||
|
@ -339,7 +339,7 @@ class MxForm(FormRevMixin, ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = Mx
|
||||
fields = ['zone', 'priority', 'name']
|
||||
fields = ['zone', 'priority', 'name', 'ttl']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||
|
@ -373,7 +373,7 @@ class NsForm(FormRevMixin, ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = Ns
|
||||
fields = ['zone', 'ns']
|
||||
fields = ['zone', 'ns', 'ttl']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||
|
|
37
machines/migrations/0103_auto_20191002_2222.py
Normal file
37
machines/migrations/0103_auto_20191002_2222.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.23 on 2019-10-02 20:22
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import machines.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('machines', '0102_auto_20190303_1611'),
|
||||
('preferences', '0066_optionalmachine_default_dns_ttl'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='domain',
|
||||
name='ttl',
|
||||
field=models.PositiveIntegerField(default=0, verbose_name='Time To Live (TTL)'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='mx',
|
||||
name='ttl',
|
||||
field=models.PositiveIntegerField(default=172800, verbose_name='Time To Live (TTL)'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='ns',
|
||||
name='ttl',
|
||||
field=models.PositiveIntegerField(default=172800, verbose_name='Time To Live (TTL)'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='txt',
|
||||
name='ttl',
|
||||
field=models.PositiveIntegerField(default=172800, verbose_name='Time To Live (TTL)'),
|
||||
),
|
||||
]
|
19
machines/migrations/0104_auto_20191002_2231.py
Normal file
19
machines/migrations/0104_auto_20191002_2231.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.23 on 2019-10-02 20:31
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('machines', '0103_auto_20191002_2222'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='domain',
|
||||
options={'permissions': (('view_domain', 'Can view a domain object'), ('change_ttl', 'Can change TTL of a domain object')), 'verbose_name': 'domain', 'verbose_name_plural': 'domains'},
|
||||
),
|
||||
]
|
20
machines/migrations/0105_dname_ttl.py
Normal file
20
machines/migrations/0105_dname_ttl.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.23 on 2019-10-02 21:47
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('machines', '0104_auto_20191002_2231'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='dname',
|
||||
name='ttl',
|
||||
field=models.PositiveIntegerField(default=172800, verbose_name='Time To Live (TTL)'),
|
||||
),
|
||||
]
|
|
@ -834,6 +834,10 @@ class Mx(RevMixin, AclMixin, models.Model):
|
|||
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
|
||||
priority = models.PositiveIntegerField()
|
||||
name = models.ForeignKey('Domain', on_delete=models.PROTECT)
|
||||
ttl = models.PositiveIntegerField(
|
||||
verbose_name=_("Time To Live (TTL)"),
|
||||
default=172800, # 2 days
|
||||
)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
@ -859,6 +863,10 @@ class Ns(RevMixin, AclMixin, models.Model):
|
|||
"""Liste des enregistrements name servers par zone considéérée"""
|
||||
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
|
||||
ns = models.ForeignKey('Domain', on_delete=models.PROTECT)
|
||||
ttl = models.PositiveIntegerField(
|
||||
verbose_name=_("Time To Live (TTL)"),
|
||||
default=172800, # 2 days
|
||||
)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
@ -881,6 +889,10 @@ class Txt(RevMixin, AclMixin, models.Model):
|
|||
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
|
||||
field1 = models.CharField(max_length=255)
|
||||
field2 = models.TextField(max_length=2047)
|
||||
ttl = models.PositiveIntegerField(
|
||||
verbose_name=_("Time To Live (TTL)"),
|
||||
default=172800, # 2 days
|
||||
)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
@ -903,6 +915,10 @@ class DName(RevMixin, AclMixin, models.Model):
|
|||
"""A DNAME entry for the DNS."""
|
||||
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
|
||||
alias = models.CharField(max_length=255)
|
||||
ttl = models.PositiveIntegerField(
|
||||
verbose_name=_("Time To Live (TTL)"),
|
||||
default=172800, # 2 days
|
||||
)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
@ -1544,7 +1560,7 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
return str(self.ipv6)
|
||||
|
||||
|
||||
class Domain(RevMixin, AclMixin, models.Model):
|
||||
class Domain(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||
""" Objet domain. Enregistrement A et CNAME en même temps : permet de
|
||||
stocker les alias et les nom de machines, suivant si interface_parent
|
||||
ou cname sont remplis"""
|
||||
|
@ -1566,11 +1582,17 @@ class Domain(RevMixin, AclMixin, models.Model):
|
|||
blank=True,
|
||||
related_name='related_domain'
|
||||
)
|
||||
ttl = models.PositiveIntegerField(
|
||||
verbose_name=_("Time To Live (TTL)"),
|
||||
default=0 # 0 means that the re2o-service for DNS should retrieve the
|
||||
# default TTL
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = (("name", "extension"),)
|
||||
permissions = (
|
||||
("view_domain", _("Can view a domain object")),
|
||||
("change_ttl", _("Can change TTL of a domain object")),
|
||||
)
|
||||
verbose_name = _("domain")
|
||||
verbose_name_plural = _("domains")
|
||||
|
@ -1728,6 +1750,15 @@ class Domain(RevMixin, AclMixin, models.Model):
|
|||
)
|
||||
return True, None, None
|
||||
|
||||
@staticmethod
|
||||
def can_change_ttl(user_request, *_args, **_kwargs):
|
||||
can = user_request.has_perm('machines.change_ttl')
|
||||
return (
|
||||
can,
|
||||
_("You don't have the right to change the domain's TTL.") if not can else None,
|
||||
('machines.change_ttl',)
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name) + str(self.extension)
|
||||
|
||||
|
|
|
@ -30,12 +30,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Aliases" %}</th>
|
||||
<th>{% trans "TTL" %}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for alias in alias_list %}
|
||||
<tr>
|
||||
<td>{{ alias }}</td>
|
||||
<td>{{ alias.ttl }}</td>
|
||||
<td class="text-right">
|
||||
{% can_edit alias %}
|
||||
{% include 'buttons/edit.html' with href='machines:edit-alias' id=alias.id %}
|
||||
|
|
|
@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<tr>
|
||||
<th>{% trans "Target zone" %}</th>
|
||||
<th>{% trans "Record" %}</th>
|
||||
<th>{% trans "TTL" %}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -36,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<tr>
|
||||
<td>{{ dname.zone }}</td>
|
||||
<td>{{ dname.dns_entry }}</td>
|
||||
<td>{{ dname.ttl }}</td>
|
||||
<td class="text-right">
|
||||
{% can_edit dname %}
|
||||
{% include 'buttons/edit.html' with href='machines:edit-dname' id=dname.id %}
|
||||
|
|
|
@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<th>{% trans "Concerned zone" %}</th>
|
||||
<th>{% trans "Priority" %}</th>
|
||||
<th>{% trans "Record" %}</th>
|
||||
<th>{% trans "TTL" %}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -40,6 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<td>{{ mx.zone }}</td>
|
||||
<td>{{ mx.priority }}</td>
|
||||
<td>{{ mx.name }}</td>
|
||||
<td>{{ mx.ttl }}</td>
|
||||
<td class="text-right">
|
||||
{% can_edit mx %}
|
||||
{% include 'buttons/edit.html' with href='machines:edit-mx' id=mx.id %}
|
||||
|
|
|
@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<tr>
|
||||
<th>{% trans "Concerned zone" %}</th>
|
||||
<th>{% trans "Authoritarian interface for the concerned zone" %}</th>
|
||||
<th>{% trans "TTL" %}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -38,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<tr>
|
||||
<td>{{ ns.zone }}</td>
|
||||
<td>{{ ns.ns }}</td>
|
||||
<td>{{ ns.ttl }}</td>
|
||||
<td class="text-right">
|
||||
{% can_edit ns %}
|
||||
{% include 'buttons/edit.html' with href='machines:edit-ns' id=ns.id %}
|
||||
|
|
|
@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<tr>
|
||||
<th>{% trans "Concerned zone" %}</th>
|
||||
<th>{% trans "Record" %}</th>
|
||||
<th>{% trans "TTL" %}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -38,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<tr>
|
||||
<td>{{ txt.zone }}</td>
|
||||
<td>{{ txt.dns_entry }}</td>
|
||||
<td>{{ txt.ttl }}</td>
|
||||
<td class="text-right">
|
||||
{% can_edit txt %}
|
||||
{% include 'buttons/edit.html' with href='machines:edit-txt' id=txt.id %}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.23 on 2019-10-02 20:22
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('preferences', '0065_auto_20191010_1227'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='optionalmachine',
|
||||
name='default_dns_ttl',
|
||||
field=models.PositiveIntegerField(default=172800, verbose_name='Default Time To Live (TTL) for CNAME, A and AAA records.'),
|
||||
),
|
||||
]
|
|
@ -173,6 +173,10 @@ class OptionalMachine(AclMixin, PreferencesModel):
|
|||
create_machine = models.BooleanField(
|
||||
default=True
|
||||
)
|
||||
default_dns_ttl = models.PositiveIntegerField(
|
||||
verbose_name=_("Default Time To Live (TTL) for CNAME, A and AAA records."),
|
||||
default=172800, # 2 days
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def ipv6(self):
|
||||
|
|
|
@ -177,10 +177,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<tr>
|
||||
<th>{% trans "Maximum number of DNS aliases allowed for a standard user" %}</th>
|
||||
<td>{{ machineoptions.max_lambdauser_aliases }}</td>
|
||||
<th>{% trans "IPv6 support" %}</th>
|
||||
<td>{{ machineoptions.ipv6_mode }}</td>
|
||||
<th>{% trans "Default Time To Live (TTL) for CNAME, A and AAA records." %}</th>
|
||||
<td>{{ machineoptions.default_dns_ttl }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans "IPv6 support" %}</th>
|
||||
<td>{{ machineoptions.ipv6_mode }}</td>
|
||||
<th>{% trans "Creation of machines" %}</th>
|
||||
<td>{{ machineoptions.create_machine|tick }}</td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in a new issue