Merge pull request #312 from elnappo/prevent_domain

add domain name check
This commit is contained in:
Fabian Weisshaar 2017-05-27 16:17:15 +02:00 committed by GitHub
commit 0d3b47773d
4 changed files with 39 additions and 10 deletions

View File

@ -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')]),
),
]

View File

@ -85,6 +85,7 @@ class Domain(models.Model):
name = models.CharField( name = models.CharField(
_("name"), _("name"),
max_length=255, # RFC 2181 (and also: max length of unique fields) 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, unique=True,
help_text=_("Name of the zone where dynamic hosts may get added")) help_text=_("Name of the zone where dynamic hosts may get added"))
nameserver_ip = models.GenericIPAddressField( nameserver_ip = models.GenericIPAddressField(

View File

@ -2,6 +2,11 @@
{% load i18n %}{% load bootstrap %} {% load i18n %}{% load bootstrap %}
{% block content %} {% block content %}
<div class="alert alert-warning" role="alert">
<i class="fa fa-exclamation-triangle"
aria-hidden="true"></i> {% trans "This feature is for advanced users only! To use this feature, you need control over at least one nameserver which is able to accept dynamic updates (RFC 2136)." %}
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
</div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="well well-sm"> <div class="well well-sm">
@ -18,14 +23,17 @@
<h3>{% trans "Help" %}</h3> <h3>{% trans "Help" %}</h3>
<p> <p>
{% blocktrans trimmed %} {% blocktrans trimmed %}
Here you can add new domains (zones) which you control (and this is only useful if you 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). have some own zone which you can update automatically).
{% endblocktrans %} {% endblocktrans %}
</p> </p>
<p> <p>
{% blocktrans trimmed %} {% blocktrans trimmed %}
You need to be able to configure the primary master nameserver of the zone so it accepts You need to be able to configure the primary master nameserver of the zone
dynamic updates (via RFC 2136 "dynamic update" protocol) if the correct update secret is presented. so it accepts
dynamic updates (via RFC 2136 "dynamic update" protocol) if the correct
update secret is presented.
{% endblocktrans %} {% endblocktrans %}
</p> </p>
<p> <p>

View File

@ -85,7 +85,7 @@
<div class="col-md-12"> <div class="col-md-12">
<h3> <h3>
{% trans "Domains (yours first, then public)" %} {% trans "Domains (yours first, then public)" %}
<a href="{% url 'add_domain' %}" class="btn btn-primary btn-sm">{% trans "Add Domain" %}</a> <a href="{% url 'add_domain' %}" class="btn btn-default btn-sm">{% trans "Add Domain" %}</a>
</h3> </h3>
<table class="table"> <table class="table">
<thead> <thead>