Url, Profile, Search
This commit is contained in:
parent
f6440a57e3
commit
faa79edfc6
|
@ -1,5 +1,7 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.auth.forms import PasswordChangeForm
|
||||||
|
from django.contrib.auth import login as auth_login
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.views.generic import CreateView
|
from django.views.generic import CreateView
|
||||||
from django.urls import reverse_lazy, reverse
|
from django.urls import reverse_lazy, reverse
|
||||||
|
@ -16,17 +18,32 @@ from .forms import CustomUserCreationForm
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def profile(request):
|
def profile(request):
|
||||||
return render(request, "profile/profile.html", {})
|
pwForm = None
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
if request.POST.get("submit", None) == "pwchange":
|
||||||
|
pwForm = PasswordChangeForm(user=request.user, data=request.POST)
|
||||||
|
if pwForm.is_valid():
|
||||||
|
pwForm.save()
|
||||||
|
auth_login(request, pwForm.user)
|
||||||
|
messages.success(request, "Password changed")
|
||||||
|
|
||||||
|
return HttpResponseRedirect(reverse("profile"))
|
||||||
|
|
||||||
|
if not pwForm:
|
||||||
|
pwForm = PasswordChangeForm(user=request.user)
|
||||||
|
|
||||||
|
return render(request, "registration/profile.html", {'pwForm': pwForm})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard(request):
|
def dashboard(request):
|
||||||
mnts = request.user.maintainer_set.all()
|
mnts = request.user.maintainer_set.all()
|
||||||
ownMnts = request.user.maintainer_set.filter(rir=False, lir=False).all()
|
ownMnts = request.user.maintainer_set.filter(rir=False, lir=False).all().distinct()
|
||||||
asns = ASNumber.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts))
|
asns = ASNumber.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts)).distinct()
|
||||||
inetnums = InetNum.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts))
|
inetnums = InetNum.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts)).distinct()
|
||||||
domains = Domain.objects.filter(mnt_by__in=mnts)
|
domains = Domain.objects.filter(mnt_by__in=mnts).distinct()
|
||||||
rrequests = Request.objects.filter((Q(provider__in=mnts) | Q(applicant__in=mnts)) & Q(status=Request.STATE_OPEN))
|
rrequests = Request.objects.filter((Q(provider__in=mnts) | Q(applicant__in=mnts)) & Q(status=Request.STATE_OPEN)).distinct()
|
||||||
|
|
||||||
return render(request, "dncore/dashboard.html", {"asns": asns, "inetnums": inetnums, "domains": domains, 'rrequests': rrequests})
|
return render(request, "dncore/dashboard.html", {"asns": asns, "inetnums": inetnums, "domains": domains, 'rrequests': rrequests})
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,11 @@
|
||||||
<div id="navbar" class="navbar-collapse collapse">
|
<div id="navbar" class="navbar-collapse collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<li{% if request.resolver_match.url_name == 'dashboard' %} class="active"{%endif%}><a href="{% url "dashboard" %}">Dashboard</a></li>
|
<li{% if request.resolver_match.namespaces|length == 0 and request.resolver_match.url_name == 'dashboard' %} class="active"{%endif%}><a href="{% url "dashboard" %}">Dashboard</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li{% if request.resolver_match.url_name == 'index' %} class="active"{%endif%}><a href="{% url "index" %}">Home</a></li>
|
<li{% if request.resolver_match.url_name == 'index' %} class="active"{%endif%}><a href="{% url "index" %}">Home</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li{% if "dncore" in request.resolver_match.app and request.resolver_match.url_name == 'search' %} class="active"{%endif%}><a href="{% url "whoisdb:search" %}">Search</a></li>
|
<li{% if request.resolver_match.url_name == 'search' %} class="active"{%endif%}><a href="{% url "whoisdb:search" %}">Search</a></li>
|
||||||
<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">
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>You don't have any domains</p>
|
<p>You don't have any ip networks</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>You don't have any open resource requests</p>
|
<p>You don't have any domains</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -9,8 +9,9 @@
|
||||||
<div class="panel-heading">User Info</div>
|
<div class="panel-heading">User Info</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label">User <span class="glyphicon glyphicon-ok-sign text-success"></span></label>
|
<label class="control-label">User</label>
|
||||||
<p class="form-control-static">{{ user }}</p>
|
<p class="form-control-static">{{ user }}</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -19,7 +20,7 @@
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">Change Password</div>
|
<div class="panel-heading">Change Password</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<form method="POST" action="{% url "profile" %}">
|
<form method="POST" action="{% url "user:profile" %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ pwForm|crispy }}
|
{{ pwForm|crispy }}
|
||||||
<button type="submit" class="btn btn-primary" name="submit" value="pwchange">Change Password</button>
|
<button type="submit" class="btn btn-primary" name="submit" value="pwchange">Change Password</button>
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import whoisdb.models
|
import whoisdb.models
|
||||||
import domains.models
|
import domains.models
|
||||||
|
|
||||||
|
from django.db.models import F
|
||||||
|
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -73,17 +75,34 @@ def findInDatabase(rawValue):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if value:
|
if value:
|
||||||
# TODO FIXME: find smallest matching network
|
# NOTE: this is only for "small subnets", we could increase this...
|
||||||
obj = whoisdb.models.InetNum.objects.filter(address=str(value))
|
baseaddr = None
|
||||||
results.extend(obj)
|
if value.version == 4:
|
||||||
|
basenet = ipaddress.ip_network("%s/24" % value, strict=False)
|
||||||
|
baseaddr = ".".join(str(basenet).split(".")[0:3]) + "."
|
||||||
|
else:
|
||||||
|
basenet = ipaddress.ip_network("%s/56" % value.exploded, strict=False)
|
||||||
|
baseaddr = ":".join(str(basenet).split(":")[0:4])[-2]
|
||||||
|
|
||||||
|
nets = whoisdb.models.InetNum.objects.filter(address__startswith=baseaddr).order_by("-netmask")
|
||||||
|
for net in nets:
|
||||||
|
if value in net.getNetwork():
|
||||||
|
results.append(net)
|
||||||
|
break
|
||||||
|
|
||||||
# asnumber?
|
# asnumber?
|
||||||
m = re.match("^(?:AS)?(\d+)$", rawValue)
|
m = re.match("^(?:AS)?(\d+)$", rawValue)
|
||||||
if m:
|
if m:
|
||||||
# asnumber!
|
# asnumber!
|
||||||
obj = whoisdb.models.ASNumber(number=int(m.group(1)))
|
num = int(m.group(1))
|
||||||
|
obj = whoisdb.models.ASNumber.objects.filter(number=num)
|
||||||
results.extend(obj)
|
results.extend(obj)
|
||||||
|
|
||||||
|
# find a matching block
|
||||||
|
blocks = whoisdb.models.ASBlock.objects.filter(asBegin__lte=num, asEnd__gte=num).annotate(size=F('asEnd')-F('asBegin')).order_by('size')
|
||||||
|
if blocks.count() > 0:
|
||||||
|
results.append(blocks[0])
|
||||||
|
|
||||||
# asblocks? smallest asblock containing the range
|
# asblocks? smallest asblock containing the range
|
||||||
# WHEN anotation foo... could also be done in asnumber match
|
# WHEN anotation foo... could also be done in asnumber match
|
||||||
# also look for number - number queries?
|
# also look for number - number queries?
|
||||||
|
|
Loading…
Reference in New Issue