diff --git a/kjg/IPv6/ula/ularegistry/forms.py b/kjg/IPv6/ula/ularegistry/forms.py index 73d2d3e..6a01ebb 100644 --- a/kjg/IPv6/ula/ularegistry/forms.py +++ b/kjg/IPv6/ula/ularegistry/forms.py @@ -10,3 +10,7 @@ class ip_random(forms.Form): NetworkName = forms.CharField() NetworkDescription = forms.CharField() +class new_ip_random(forms.Form): + NetworkName = forms.CharField() + NetworkDescription = forms.CharField() + diff --git a/kjg/IPv6/ula/ularegistry/templates/newrandomIP.html b/kjg/IPv6/ula/ularegistry/templates/newrandomIP.html new file mode 100644 index 0000000..15098ab --- /dev/null +++ b/kjg/IPv6/ula/ularegistry/templates/newrandomIP.html @@ -0,0 +1,16 @@ +
+ {% csrf_token %} + + {{ form2 }} +
+ +
+{% if ips_listr %} + +{% else %} +

No registered IP.

+{% endif %} diff --git a/kjg/IPv6/ula/ularegistry/urls.py b/kjg/IPv6/ula/ularegistry/urls.py index 14385cb..9380342 100644 --- a/kjg/IPv6/ula/ularegistry/urls.py +++ b/kjg/IPv6/ula/ularegistry/urls.py @@ -5,4 +5,5 @@ from . import views urlpatterns = [ path('', views.index, name='index'), path('randomIP', views.randomIP, name='randomIP'), + path('newrandomIP', views.newrandomIP, name='newrandomIP'), ] diff --git a/kjg/IPv6/ula/ularegistry/views.py b/kjg/IPv6/ula/ularegistry/views.py index f787768..647fa17 100644 --- a/kjg/IPv6/ula/ularegistry/views.py +++ b/kjg/IPv6/ula/ularegistry/views.py @@ -1,6 +1,6 @@ from django.shortcuts import render from django.http import HttpResponse -from .forms import ip, ip_random +from .forms import ip_random, new_ip_random, ip from ularegistry.models import ips, ips2 from django.shortcuts import redirect from ularegistry.checkip import * @@ -84,3 +84,43 @@ def randomIP(request): return render(request, 'randomIP.html', ctx) +def newrandomIP(request): + ips_listr = ips2.objects.values() + if request.method == "POST": + form2 = new_ip_random(request.POST) + print(form2) + if form2.is_valid(): + while True: + newIP = createIP("fd00::/8") + print("test3") + ips_listr2 = list(ips_listr) + if not ips_listr2: + print("test2") + q = ips2(inet2=newIP, inet2_name=form2.cleaned_data['NetworkName'], inet2_descrip=form2.cleaned_data['NetworkDescription']) + q.save() + break + + overlapchk = 0 + + for value in ips_listr2: + if overlapip(newIP,value['inet2']): + overlapchk = 1 + print(overlapchk) + q = ips2(inet2=newIP, inet2_name=form2.cleaned_data['NetworkName'], inet2_descrip=form2.cleaned_data['NetworkDescription']) + q.save() + break + else: + overlapchk = 0 + + if overlapchk: + break + + return redirect('newrandomIP') + + else: + form2 = new_ip_random() + + ctx2 = { 'form2' : form2, + 'ips_listr' : ips_listr, + } + return render(request, 'newrandomIP.html', ctx2)