mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 08:32:26 +00:00
Fix #212
This commit is contained in:
parent
0d8bc2c578
commit
aab6fa2ba0
11 changed files with 132 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', '0064_optionalmachine_default_dns_ttl'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='domain',
|
||||
name='ttl',
|
||||
field=models.PositiveIntegerField(default=machines.models.get_default_ttl, 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'},
|
||||
),
|
||||
]
|
|
@ -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 = (
|
||||
|
@ -1544,7 +1556,11 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
return str(self.ipv6)
|
||||
|
||||
|
||||
class Domain(RevMixin, AclMixin, models.Model):
|
||||
def get_default_ttl():
|
||||
return preferences.models.OptionalMachine.get_cached_value('default_dns_ttl')
|
||||
|
||||
|
||||
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,16 @@ class Domain(RevMixin, AclMixin, models.Model):
|
|||
blank=True,
|
||||
related_name='related_domain'
|
||||
)
|
||||
ttl = models.PositiveIntegerField(
|
||||
verbose_name=_("Time To Live (TTL)"),
|
||||
default=get_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 +1749,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 %}
|
||||
|
|
|
@ -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', '0063_mandate'),
|
||||
]
|
||||
|
||||
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