From f3d2d031b056e36f9f069c0bed65e49a42bd5f8b Mon Sep 17 00:00:00 2001 From: Fabian Weisshaar Date: Fri, 26 May 2017 18:29:07 +0200 Subject: [PATCH] add domain name check, fixes #308 --- .../migrations/0011_auto_20170526_2113.py | 20 ++++++++++++++ nsupdate/main/models.py | 1 + nsupdate/main/templates/main/domain_add.html | 26 ++++++++++++------- nsupdate/main/templates/main/overview.html | 2 +- 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 nsupdate/main/migrations/0011_auto_20170526_2113.py diff --git a/nsupdate/main/migrations/0011_auto_20170526_2113.py b/nsupdate/main/migrations/0011_auto_20170526_2113.py new file mode 100644 index 0000000..f7721bd --- /dev/null +++ b/nsupdate/main/migrations/0011_auto_20170526_2113.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.core.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0010_auto_20151229_1717'), + ] + + operations = [ + migrations.AlterField( + model_name='domain', + name='name', + field=models.CharField(help_text='Name of the zone where dynamic hosts may get added', unique=True, max_length=255, verbose_name='name', validators=[django.core.validators.RegexValidator(regex=b'([a-zA-Z0-9-_]+\\.)+[a-zA-Z0-9-_]{2,}', message='Invalid domain name')]), + ), + ] diff --git a/nsupdate/main/models.py b/nsupdate/main/models.py index 1a3fcef..57930c7 100644 --- a/nsupdate/main/models.py +++ b/nsupdate/main/models.py @@ -85,6 +85,7 @@ class Domain(models.Model): name = models.CharField( _("name"), max_length=255, # RFC 2181 (and also: max length of unique fields) + validators=[RegexValidator(regex=r"([a-zA-Z0-9-_]+\.)+[a-zA-Z0-9-_]{2,}", message=_("Invalid domain name"))], unique=True, help_text=_("Name of the zone where dynamic hosts may get added")) nameserver_ip = models.GenericIPAddressField( diff --git a/nsupdate/main/templates/main/domain_add.html b/nsupdate/main/templates/main/domain_add.html index e417afe..e870926 100644 --- a/nsupdate/main/templates/main/domain_add.html +++ b/nsupdate/main/templates/main/domain_add.html @@ -2,6 +2,11 @@ {% load i18n %}{% load bootstrap %} {% block content %} +
@@ -17,19 +22,22 @@

{% trans "Help" %}

- {% blocktrans trimmed %} - Here you can add new domains (zones) which you control (and this is only useful if you - have some own zone which you can update automatically). - {% endblocktrans %} + {% blocktrans trimmed %} + Here you can add new domains (zones) which you control (and this is only + useful if you + have some own zone which you can update automatically). + {% endblocktrans %}

- {% blocktrans trimmed %} - You need to be able to configure the primary master nameserver of the zone so it accepts - dynamic updates (via RFC 2136 "dynamic update" protocol) if the correct update secret is presented. - {% endblocktrans %} + {% blocktrans trimmed %} + You need to be able to configure the primary master nameserver of the zone + so it accepts + dynamic updates (via RFC 2136 "dynamic update" protocol) if the correct + update secret is presented. + {% endblocktrans %}

- {% trans "We'll show you configuration examples after you add a domain." %} + {% trans "We'll show you configuration examples after you add a domain." %}

diff --git a/nsupdate/main/templates/main/overview.html b/nsupdate/main/templates/main/overview.html index c3bfc68..3c1ef2b 100644 --- a/nsupdate/main/templates/main/overview.html +++ b/nsupdate/main/templates/main/overview.html @@ -85,7 +85,7 @@

{% trans "Domains (yours first, then public)" %} - {% trans "Add Domain" %} + {% trans "Add Domain" %}