diff --git a/machines/forms.py b/machines/forms.py
index 6a9f287d..b85fd967 100644
--- a/machines/forms.py
+++ b/machines/forms.py
@@ -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__)
diff --git a/machines/migrations/0103_auto_20191002_2222.py b/machines/migrations/0103_auto_20191002_2222.py
new file mode 100644
index 00000000..43adac74
--- /dev/null
+++ b/machines/migrations/0103_auto_20191002_2222.py
@@ -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)'),
+ ),
+ ]
diff --git a/machines/migrations/0104_auto_20191002_2231.py b/machines/migrations/0104_auto_20191002_2231.py
new file mode 100644
index 00000000..344bddb7
--- /dev/null
+++ b/machines/migrations/0104_auto_20191002_2231.py
@@ -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'},
+ ),
+ ]
diff --git a/machines/migrations/0105_dname_ttl.py b/machines/migrations/0105_dname_ttl.py
new file mode 100644
index 00000000..d3c38073
--- /dev/null
+++ b/machines/migrations/0105_dname_ttl.py
@@ -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)'),
+ ),
+ ]
diff --git a/machines/models.py b/machines/models.py
index 97881438..ca881033 100644
--- a/machines/models.py
+++ b/machines/models.py
@@ -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)
diff --git a/machines/templates/machines/aff_alias.html b/machines/templates/machines/aff_alias.html
index 15b765c9..8fe7260c 100644
--- a/machines/templates/machines/aff_alias.html
+++ b/machines/templates/machines/aff_alias.html
@@ -30,12 +30,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% for alias in alias_list %}
{% trans "Aliases" %}
+ {% trans "TTL" %}