diff --git a/nsupdate/main/forms.py b/nsupdate/main/forms.py index 5d2dc5e..5823892 100644 --- a/nsupdate/main/forms.py +++ b/nsupdate/main/forms.py @@ -3,7 +3,13 @@ from django import forms from main.models import Host -class HostForm(forms.ModelForm): +class CreateHostForm(forms.ModelForm): class Meta: model = Host - fields = ['subdomain', 'domain', 'comment', 'update_secret'] + fields = ['subdomain', 'domain', 'comment'] + + +class EditHostForm(forms.ModelForm): + class Meta: + model = Host + fields = ['comment'] diff --git a/nsupdate/main/models.py b/nsupdate/main/models.py index 54cd677..0977cbf 100644 --- a/nsupdate/main/models.py +++ b/nsupdate/main/models.py @@ -4,6 +4,7 @@ from django.core.exceptions import ValidationError from django.core.validators import RegexValidator from django.conf import settings from django.db.models.signals import post_save +from django.contrib.auth.hashers import make_password from main import dnstools import re @@ -25,7 +26,6 @@ class BlacklistedDomain(models.Model): def domain_blacklist_validator(value): for bd in BlacklistedDomain.objects.all(): - print bd.domain if re.search(bd.domain, value): raise ValidationError(u'This domain is not allowed') @@ -69,6 +69,19 @@ class Host(models.Model): def get_fqdn(self): return self.subdomain+'.'+self.domain.domain + def generate_secret(self): + # note: we use a quick hasher for the update_secret as expensive + # more modern hashes might put too much load on the servers. also + # many update clients might use http without ssl, so it is not too + # secure anyway. + secret = User.objects.make_random_password() + self.update_secret = make_password( + secret, + hasher='sha1' + ) + self.save() + return secret + def post_delete_host(sender, **kwargs): obj = kwargs['instance'] diff --git a/nsupdate/main/templates/main/generate_secret.html b/nsupdate/main/templates/main/generate_secret.html new file mode 100644 index 0000000..876f272 --- /dev/null +++ b/nsupdate/main/templates/main/generate_secret.html @@ -0,0 +1,13 @@ +{% extends "base.html" %} +{% load bootstrap %} + +{% block content %} + +
New secret generated for you. We store it hashed, so save it now, or you have to generate a new one again.
+secret: {{ update_secret }}
+You can only change the comment. If you want to have another domain name, you have to delete this host and create a new one.
We store your update secret hashed, so if you forgot or lost it you have to create a new one.
+Usually you configure your router to follow the dyndns protocol. But if you know what you are doing, and you want to update it by hand, you can do it here.