2013-09-28 10:44:29 +02:00
|
|
|
from django.db import models
|
2013-09-29 14:08:22 +02:00
|
|
|
from django.core.exceptions import ValidationError
|
2013-09-29 13:36:28 +02:00
|
|
|
from django.core.validators import RegexValidator
|
2013-09-28 18:02:13 +02:00
|
|
|
from django.contrib.auth.models import User
|
2013-09-28 20:01:09 +02:00
|
|
|
from django.forms import ModelForm
|
2013-09-28 18:02:13 +02:00
|
|
|
|
2013-09-29 14:08:22 +02:00
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
class BlacklistedDomain(models.Model):
|
|
|
|
domain = models.CharField(max_length=256, unique=True, help_text='Blacklisted domain. Evaluated as regex (search).')
|
|
|
|
|
|
|
|
last_update = models.DateTimeField(auto_now=True)
|
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
created_by = models.ForeignKey(User)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u"%s" % (self.domain)
|
|
|
|
|
|
|
|
|
|
|
|
def domain_blacklist_validator(value):
|
|
|
|
for bd in BlacklistedDomain.objects.all():
|
|
|
|
if re.search(bd.domain, value):
|
|
|
|
raise ValidationError(u'This domain is not allowed')
|
|
|
|
|
2013-09-28 18:02:13 +02:00
|
|
|
|
2013-09-29 13:36:28 +02:00
|
|
|
class Domain(models.Model):
|
|
|
|
domain = models.CharField(max_length=256, unique=True)
|
|
|
|
|
|
|
|
last_update = models.DateTimeField(auto_now=True)
|
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
created_by = models.ForeignKey(User)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u"%s" % (self.domain)
|
|
|
|
|
|
|
|
|
2013-09-28 18:02:13 +02:00
|
|
|
class Host(models.Model):
|
2013-09-29 13:36:28 +02:00
|
|
|
"""TODO: hash update_secret on save (if not already hashed)"""
|
|
|
|
#fqdn = models.CharField(max_length=256, unique=True, verbose_name="Fully qualified domain name")
|
2013-09-29 13:47:02 +02:00
|
|
|
subdomain = models.CharField(max_length=256, validators=[
|
|
|
|
RegexValidator(regex=r'^(([a-z0-9][a-z0-9\-]*[a-z0-9])|[a-z0-9])$', message='Invalid subdomain: only letters, digits and dashes are allowed')])
|
2013-09-29 13:36:28 +02:00
|
|
|
domain = models.ForeignKey(Domain)
|
2013-09-28 18:02:13 +02:00
|
|
|
update_secret = models.CharField(max_length=256)
|
2013-09-29 01:21:44 +02:00
|
|
|
comment = models.CharField(max_length=256, default='', blank=True, null=True)
|
2013-09-28 18:02:13 +02:00
|
|
|
|
|
|
|
last_update = models.DateTimeField(auto_now=True)
|
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
created_by = models.ForeignKey(User)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2013-09-29 13:36:28 +02:00
|
|
|
return u"%s.%s - %s" % (self.subdomain, self.domain.domain, self.comment)
|
2013-09-28 10:44:29 +02:00
|
|
|
|
2013-09-29 13:36:28 +02:00
|
|
|
class Meta:
|
|
|
|
unique_together = (('subdomain', 'domain'),)
|
2013-09-28 20:01:09 +02:00
|
|
|
|