noot
This commit is contained in:
parent
4303a1d674
commit
e3311a6df7
|
@ -9,9 +9,44 @@
|
||||||
<div class="panel-heading">Header</div>
|
<div class="panel-heading">Header</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{% if mnts %}
|
{% if mnts %}
|
||||||
|
<ul>
|
||||||
|
<li><a href="">Create new Maintainer</a></li>
|
||||||
|
<li><a href="">Create new Role/Person</a></li>
|
||||||
|
<li><a href="">Request resources</a></li>
|
||||||
|
{% if netblock %}
|
||||||
|
<li><a href="">Create Subnet</a></li>
|
||||||
|
{% endif %}
|
||||||
|
{% if asblock %}
|
||||||
|
<li><a href="">Create AS</a></li>
|
||||||
|
<li><a href="">Create ASblock</a></li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
{% else %}
|
You have the following Maintainers associated with you
|
||||||
You don't have a maintainer! Start by creating a Maintainer and a Person Object!
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Handle</th>
|
||||||
|
<th>Name?</th>
|
||||||
|
<th>Contact</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for mnt in mnts %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ mnt.handle }}</td>
|
||||||
|
<td>{{ mnt.description }}</td>
|
||||||
|
<td>{% for contact in mnt.admin_c.all %}{{ contact }}{% endfor %}</td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
You don't have a maintainer! Start by creating a Maintainer and a Person Object!
|
||||||
|
|
||||||
<form action="{% url "whoisdb:dashboard" %}" method="post">
|
<form action="{% url "whoisdb:dashboard" %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
|
@ -1,42 +1,88 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from dncore.models import User
|
from dncore.models import User
|
||||||
from .validators import HandleValidator
|
from .validators import HandleValidator, HandleValidatorWithSuffix
|
||||||
|
|
||||||
|
|
||||||
class WhoisObject(models.Model):
|
class WhoisObject(models.Model):
|
||||||
handle_suffix = ""
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
handleSuffix = ""
|
||||||
|
|
||||||
handle = models.SlugField(max_length=32, unique=True, verbose_name='handle', validators=[HandleValidator()])
|
handle = models.SlugField(max_length=32, unique=True, verbose_name='handle', validators=[HandleValidator()])
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
last_modified = models.DateTimeField(auto_now_add=True)
|
last_modified = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
class Meta:
|
def __str__(self):
|
||||||
abstract = True
|
return self.handle
|
||||||
|
|
||||||
|
def genHandle(self, main=None):
|
||||||
|
if not main:
|
||||||
|
main = self.name
|
||||||
|
prefix = ""
|
||||||
|
if " " in main:
|
||||||
|
parts = main.split(" ")
|
||||||
|
prefix = "".join(map(lambda _x: _x[0], parts))
|
||||||
|
if len(prefix) < 3 and len(parts[-1]) > 1:
|
||||||
|
prefix += parts[-1][1:4 - len(prefix)]
|
||||||
|
else:
|
||||||
|
prefix = main[0:3]
|
||||||
|
prefix = prefix.upper()
|
||||||
|
|
||||||
|
i = 1
|
||||||
|
handle = "%s%%d-%s" % (prefix, self.handleSuffix)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
prefix
|
||||||
|
self.__class__.objects.get(handle=handle % i)
|
||||||
|
i += 1
|
||||||
|
except self.DoesNotExist:
|
||||||
|
break
|
||||||
|
|
||||||
|
return handle % i
|
||||||
|
|
||||||
|
def handleAuto(self, name=None):
|
||||||
|
if self.handle == "AUTO":
|
||||||
|
self.handle = self.genHandle(name)
|
||||||
|
|
||||||
|
|
||||||
class Maintainer(WhoisObject):
|
class Maintainer(WhoisObject):
|
||||||
|
handleSuffix = "MNT"
|
||||||
|
|
||||||
auth = models.ManyToManyField(User)
|
auth = models.ManyToManyField(User)
|
||||||
|
handle = models.SlugField(max_length=32, unique=True, verbose_name='handle', validators=[HandleValidatorWithSuffix('MNT')])
|
||||||
description = models.CharField(max_length=64, blank=True)
|
description = models.CharField(max_length=64, blank=True)
|
||||||
|
|
||||||
admin_c = models.ManyToManyField("Contact")
|
admin_c = models.ManyToManyField("Contact")
|
||||||
|
|
||||||
class MntdObject(WhoisObject):
|
# autoInclude = models.BooleanField(default=True)
|
||||||
mnt_by = models.ManyToManyField(Maintainer)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MntdObject(WhoisObject):
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
mnt_by = models.ManyToManyField(Maintainer)
|
||||||
|
|
||||||
|
|
||||||
class Contact(MntdObject):
|
class Contact(MntdObject):
|
||||||
|
handleSuffix = "DN"
|
||||||
TYPE = (('person', 'person'), ('role', 'role'))
|
TYPE = (('person', 'person'), ('role', 'role'))
|
||||||
|
|
||||||
name = models.CharField(max_length=128)
|
name = models.CharField(max_length=128)
|
||||||
|
|
||||||
|
|
||||||
class ASBlock(MntdObject):
|
class ASBlock(MntdObject):
|
||||||
|
handleSuffix = "ASB"
|
||||||
|
|
||||||
parent_block = models.ForeignKey("ASBlock", models.CASCADE, null=True, blank=True, default=None)
|
parent_block = models.ForeignKey("ASBlock", models.CASCADE, null=True, blank=True, default=None)
|
||||||
description = models.CharField(max_length=64, blank=True)
|
description = models.CharField(max_length=64, blank=True)
|
||||||
|
|
||||||
|
|
||||||
class ASNumber(MntdObject):
|
class ASNumber(MntdObject):
|
||||||
|
handleSuffix = "AS"
|
||||||
|
|
||||||
number = models.PositiveIntegerField(unique=True, db_index=True)
|
number = models.PositiveIntegerField(unique=True, db_index=True)
|
||||||
volatile = models.BooleanField(default=False)
|
volatile = models.BooleanField(default=False)
|
||||||
asblock = models.ForeignKey(ASBlock, models.CASCADE)
|
asblock = models.ForeignKey(ASBlock, models.CASCADE)
|
||||||
|
@ -44,10 +90,10 @@ class ASNumber(MntdObject):
|
||||||
|
|
||||||
mnt_lower = models.ManyToManyField(Maintainer, related_name='lower_asnumber_set')
|
mnt_lower = models.ManyToManyField(Maintainer, related_name='lower_asnumber_set')
|
||||||
|
|
||||||
#class Route(MntObject):
|
|
||||||
#
|
|
||||||
|
|
||||||
class InetNum(WhoisObject):
|
class InetNum(WhoisObject):
|
||||||
|
handleSuffix = "NET"
|
||||||
|
|
||||||
PROTO = (('ipv4', 'ipv4'), ('ipv6', 'ipv6'))
|
PROTO = (('ipv4', 'ipv4'), ('ipv6', 'ipv6'))
|
||||||
protocol = models.CharField(max_length=4, choices=PROTO)
|
protocol = models.CharField(max_length=4, choices=PROTO)
|
||||||
netmask = models.PositiveIntegerField()
|
netmask = models.PositiveIntegerField()
|
||||||
|
|
|
@ -5,11 +5,25 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
@deconstructible
|
@deconstructible
|
||||||
class HandleValidator(validators.RegexValidator):
|
class HandleValidator(validators.RegexValidator):
|
||||||
regex = r'^[A-Z]+[0-9]+(-[A-Z]+)'
|
regex = r'^(?:[A-Z]+[0-9]+(-[A-Z]+)|AUTO)'
|
||||||
message = _(
|
message = _(
|
||||||
'Enter a valid handle (all uppercase)'
|
'Enter a valid handle (all uppercase)'
|
||||||
)
|
)
|
||||||
flags = re.ASCII if six.PY3 else 0
|
flags = re.ASCII if six.PY3 else 0
|
||||||
|
|
||||||
|
|
||||||
|
@deconstructible
|
||||||
|
class HandleValidatorWithSuffix(validators.RegexValidator):
|
||||||
|
flags = re.ASCII if six.PY3 else 0
|
||||||
|
|
||||||
|
def __init__(self, suffix):
|
||||||
|
self.regex = r'^(?:[A-Z]+[0-9]+-%s|AUTO)' % re.escape(suffix)
|
||||||
|
print(self.regex)
|
||||||
|
self.message = _(
|
||||||
|
'Enter a valid handle with suffix %s (all uppercase)' % suffix
|
||||||
|
)
|
||||||
|
|
||||||
|
super(HandleValidatorWithSuffix, self).__init__()
|
||||||
|
|
|
@ -5,27 +5,42 @@ from django.urls import reverse
|
||||||
|
|
||||||
from .forms import MntForm, ContactForm
|
from .forms import MntForm, ContactForm
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def dbDashboard(request):
|
def dbDashboard(request):
|
||||||
mnts = request.user.maintainer_set.all()
|
mnts = request.user.maintainer_set.all()
|
||||||
|
|
||||||
mntForm = contactForm = None
|
mntForm = contactForm = None
|
||||||
if request.method == "POST":
|
|
||||||
mntForm = MntForm(data=request.POST, prefix="mnt_")
|
|
||||||
contactForm = ContactForm(person=True, data=request.POST, prefix="contact")
|
|
||||||
if mntForm.is_valid() and contactForm.is_valid():
|
|
||||||
print("NOOT")
|
|
||||||
|
|
||||||
#return HttpResponseRedirect(reverse("whoisdb:dashboard"))
|
if mnts.count() == 0:
|
||||||
|
mntForm = contactForm = None
|
||||||
|
if request.method == "POST":
|
||||||
|
mntForm = MntForm(data=request.POST, prefix="mnt")
|
||||||
|
contactForm = ContactForm(person=True, data=request.POST, prefix="contact")
|
||||||
|
if mntForm.is_valid() and contactForm.is_valid():
|
||||||
|
mnt = mntForm.save(commit=False)
|
||||||
|
mnt.handleAuto(request.user.username)
|
||||||
|
mnt.save()
|
||||||
|
|
||||||
|
contact = contactForm.save(commit=False)
|
||||||
|
contact.handleAuto()
|
||||||
|
contact.save()
|
||||||
|
contact.mnt_by.add(mnt.id)
|
||||||
|
contact.save()
|
||||||
|
|
||||||
|
mnt.auth.add(request.user.id)
|
||||||
|
mnt.admin_c.add(contact.id)
|
||||||
|
mnt.save()
|
||||||
|
|
||||||
|
return HttpResponseRedirect(reverse("whoisdb:dashboard"))
|
||||||
|
else:
|
||||||
|
mntForm = MntForm(prefix="mnt", initial={'handle': 'AUTO', 'description': 'Primary maintainer of %s' % request.user.username})
|
||||||
|
contactForm = ContactForm(person=True, initial={'handle': 'AUTO', 'name': request.user.username.capitalize()}, prefix='contact')
|
||||||
|
|
||||||
mntForm = MntForm(prefix="mnt", initial={'handle': 'AUTO', 'description': 'Main maintainer of %s' % request.user.username})
|
|
||||||
contactForm = ContactForm(person=True, initial={'handle': 'AUTO'}, prefix='contact_')
|
|
||||||
return render(request, "whoisdb/overview.html", {"mnts": mnts, "mntForm": mntForm, "contactForm": contactForm})
|
return render(request, "whoisdb/overview.html", {"mnts": mnts, "mntForm": mntForm, "contactForm": contactForm})
|
||||||
|
|
||||||
|
|
||||||
def manageMnt(request, mnt=None):
|
def manageMnt(request, mnt=None):
|
||||||
if mnt:
|
if mnt:
|
||||||
# object or 404
|
# object or 404
|
||||||
pass
|
pass
|
||||||
return render(request, "whoisdb/overview.html", {})
|
return render(request, "whoisdb/overview.html", {})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue