from django.shortcuts import render from django.http import HttpResponse from .forms import ip_random, new_ip_random, ip from ularegistry.models import ips, ips2 from django.shortcuts import redirect from ularegistry.checkip import * from ularegistry.randomcreate import * # Create your views here. def index(request): ips_list = ips.objects.values() if request.method == "POST": form = ip(request.POST) print(form) if form.is_valid(): ips_list2 = list(ips_list) if not ips_list2: print("test") q = ips(inet=form.cleaned_data['inputIP']) q.save() overlapchk = 0 for value in ips_list2: if overlapip(form.cleaned_data['inputIP'],value['inet']): overlapchk = 1 else: overlapchk = 0 break if overlapchk: print(overlapchk) q = ips(inet=form.cleaned_data['inputIP']) q.save() return redirect('index') else: form = ip() ctx = { 'form' : form, 'ips_list' : ips_list, } return render(request, 'index.html', ctx) #return HttpResponse("Hello, world.") def randomIP(request): ips_listr = ips2.objects.values() if request.method == "POST": form = ip_random(request.POST) print(form) if form.is_valid(): while True: newIP = createIP(form.cleaned_data['inputNetwork']) ips_listr2 = list(ips_listr) if not ips_listr2: print("test") q = ips2(inet2=newIP, inet2_name=form.cleaned_data['NetworkName'], inet2_descrip=form.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=form.cleaned_data['NetworkName'], inet2_descrip=form.cleaned_data['NetworkDescription']) q.save() break else: overlapchk = 0 if overlapchk: break return redirect('randomIP') else: form = ip_random() ctx = { 'form' : form, 'ips_listr' : ips_listr, } 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)