This commit is contained in:
Sebastian Lohff 2017-02-23 22:28:06 +01:00
parent d49a3c2774
commit 4303a1d674
11 changed files with 286 additions and 9 deletions

4
README Normal file
View File

@ -0,0 +1,4 @@
whoisdb
see own objects
list of all ASses?

View File

@ -47,7 +47,7 @@
<li class="dropdown{% if request.resolver_match.url_name == 'whoisdb' %} active{%endif%}"> <li class="dropdown{% if request.resolver_match.url_name == 'whoisdb' %} active{%endif%}">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Whois DB <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Whois DB <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#">Noot</a></li> <li><a href="{% url "whoisdb:dashboard" %}">Overview</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -0,0 +1,35 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Header</div>
<div class="panel-body">
{% if mnts %}
{% else %}
You don't have a maintainer! Start by creating a Maintainer and a Person Object!
<form action="{% url "whoisdb:dashboard" %}" method="post">
{% csrf_token %}
<h3>Maintainer Object</h3>
<small>This object will be used to identify resources you are allowed
to edit via your maintainer</small>
{{ mntForm | crispy }}
<h3>Person Object</h3>
<small>This object will be used to identify yourself as a person to other people, used for your maintainer object</small>
{{ contactForm | crispy }}
<button type="submit" class="btn btn-primary">Create</button>
</form>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -1,3 +1,9 @@
from django.contrib import admin from django.contrib import admin
# Register your models here. from .models import Maintainer, Contact, ASBlock, ASNumber, InetNum
admin.site.register(Maintainer)
admin.site.register(Contact)
admin.site.register(ASBlock)
admin.site.register(ASNumber)
admin.site.register(InetNum)

22
whoisdb/forms.py Normal file
View File

@ -0,0 +1,22 @@
from django import forms
#from crispy_forms.helper import FormHelper
#from crispy_forms.layout import Submit, Layout
#from django.urls import reverse
from .models import Maintainer, Contact
class MntForm(forms.ModelForm):
class Meta:
model = Maintainer
fields = ['handle', 'description']
class ContactForm(forms.ModelForm):
class Meta:
model = Contact
fields = ['handle', 'name']
def __init__(self, person=True, *args, **kwargs):
super(ContactForm, self).__init__(*args, **kwargs)
# check if this is a person
self.person = person

View File

@ -0,0 +1,133 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-21 22:40
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import whoisdb.validators
class Migration(migrations.Migration):
dependencies = [
('whoisdb', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='ASBlock',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('handle', models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()])),
('created', models.DateTimeField(auto_now_add=True)),
('last_modified', models.DateTimeField(auto_now_add=True)),
('description', models.CharField(blank=True, max_length=64)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ASNumber',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('handle', models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()])),
('created', models.DateTimeField(auto_now_add=True)),
('last_modified', models.DateTimeField(auto_now_add=True)),
('number', models.PositiveIntegerField(db_index=True, unique=True)),
('volatile', models.BooleanField(default=False)),
('description', models.CharField(blank=True, max_length=64)),
('asblock', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='whoisdb.ASBlock')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Contact',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('handle', models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()])),
('created', models.DateTimeField(auto_now_add=True)),
('last_modified', models.DateTimeField(auto_now_add=True)),
('name', models.CharField(max_length=128)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='InetNum',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('handle', models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()])),
('created', models.DateTimeField(auto_now_add=True)),
('last_modified', models.DateTimeField(auto_now_add=True)),
('protocol', models.CharField(choices=[('ipv4', 'ipv4'), ('ipv6', 'ipv6')], max_length=4)),
('netmask', models.PositiveIntegerField()),
('description', models.CharField(blank=True, max_length=64)),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='maintainer',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='maintainer',
name='handle',
field=models.SlugField(default=None, max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()]),
preserve_default=False,
),
migrations.AddField(
model_name='maintainer',
name='last_modified',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='inetnum',
name='mnt_lower',
field=models.ManyToManyField(to='whoisdb.Maintainer'),
),
migrations.AddField(
model_name='inetnum',
name='parent_range',
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='whoisdb.InetNum'),
),
migrations.AddField(
model_name='contact',
name='mnt_by',
field=models.ManyToManyField(to='whoisdb.Maintainer'),
),
migrations.AddField(
model_name='asnumber',
name='mnt_by',
field=models.ManyToManyField(to='whoisdb.Maintainer'),
),
migrations.AddField(
model_name='asnumber',
name='mnt_lower',
field=models.ManyToManyField(related_name='lower_asnumber_set', to='whoisdb.Maintainer'),
),
migrations.AddField(
model_name='asblock',
name='mnt_by',
field=models.ManyToManyField(to='whoisdb.Maintainer'),
),
migrations.AddField(
model_name='asblock',
name='parent_block',
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='whoisdb.ASBlock'),
),
migrations.AddField(
model_name='maintainer',
name='admin_c',
field=models.ManyToManyField(to='whoisdb.Contact'),
),
]

View File

@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-22 18:12
from __future__ import unicode_literals
from django.db import migrations, models
import whoisdb.validators
class Migration(migrations.Migration):
dependencies = [
('whoisdb', '0002_auto_20170221_2240'),
]
operations = [
migrations.AddField(
model_name='maintainer',
name='description',
field=models.CharField(blank=True, max_length=64),
),
migrations.AlterField(
model_name='asblock',
name='handle',
field=models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()], verbose_name='name'),
),
migrations.AlterField(
model_name='asnumber',
name='handle',
field=models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()], verbose_name='name'),
),
migrations.AlterField(
model_name='contact',
name='handle',
field=models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()], verbose_name='name'),
),
migrations.AlterField(
model_name='inetnum',
name='handle',
field=models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()], verbose_name='name'),
),
migrations.AlterField(
model_name='maintainer',
name='handle',
field=models.SlugField(max_length=32, unique=True, validators=[whoisdb.validators.HandleValidator()], verbose_name='name'),
),
]

View File

@ -5,17 +5,18 @@ from .validators import HandleValidator
class WhoisObject(models.Model): class WhoisObject(models.Model):
handle_suffix = None handle_suffix = ""
handle = models.SlugField(max_length='32', unique=True, validators=[HandleValidator()]) handle = models.SlugField(max_length=32, unique=True, verbose_name='handle', validators=[HandleValidator()])
created = models.DateTimeField(auto_add_now=True) created = models.DateTimeField(auto_now_add=True)
last_modified = models.DateTimeField(auto_add_now=True) last_modified = models.DateTimeField(auto_now_add=True)
class Meta: class Meta:
abstract = True abstract = True
class Maintainer(WhoisObject): class Maintainer(WhoisObject):
auth = models.ManyToManyField(User) auth = models.ManyToManyField(User)
description = models.CharField(max_length=64, blank=True)
admin_c = models.ManyToManyField("Contact") admin_c = models.ManyToManyField("Contact")
@ -41,7 +42,7 @@ class ASNumber(MntdObject):
asblock = models.ForeignKey(ASBlock, models.CASCADE) asblock = models.ForeignKey(ASBlock, models.CASCADE)
description = models.CharField(max_length=64, blank=True) description = models.CharField(max_length=64, blank=True)
mnt_lower = models.ManyToManyField(Maintainer) mnt_lower = models.ManyToManyField(Maintainer, related_name='lower_asnumber_set')
#class Route(MntObject): #class Route(MntObject):
# #

View File

@ -3,6 +3,6 @@ from django.conf.urls import url
from . import views as whoisdb_views from . import views as whoisdb_views
urlpatterns = [ urlpatterns = [
#url(r'^$', dncore_views.dashboard, name='dashboard'), url(r'^$', whoisdb_views.dbDashboard, name='dashboard'),
] ]

View File

@ -3,6 +3,8 @@ from django.utils import six
from django.utils.deconstruct import deconstructible from django.utils.deconstruct import deconstructible
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
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]+)'

View File

@ -1,3 +1,31 @@
from django.shortcuts import render from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.urls import reverse
from .forms import MntForm, ContactForm
@login_required
def dbDashboard(request):
mnts = request.user.maintainer_set.all()
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"))
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})
def manageMnt(request, mnt=None):
if mnt:
# object or 404
pass
return render(request, "whoisdb/overview.html", {})
# Create your views here.