Browse Source

Url, Profile, Search

Sebastian Lohff 2 years ago
parent
commit
faa79edfc6
5 changed files with 53 additions and 16 deletions
  1. 23
    6
      dncore/views.py
  2. 2
    2
      templates/base.html
  3. 2
    2
      templates/dncore/dashboard.html
  4. 3
    2
      templates/registration/profile.html
  5. 23
    4
      whoisdb/helpers.py

+ 23
- 6
dncore/views.py View File

@@ -1,5 +1,7 @@
1 1
 from django.shortcuts import render
2 2
 from django.contrib.auth.decorators import login_required
3
+from django.contrib.auth.forms import PasswordChangeForm
4
+from django.contrib.auth import login as auth_login
3 5
 from django.db.models import Q
4 6
 from django.views.generic import CreateView
5 7
 from django.urls import reverse_lazy, reverse
@@ -16,17 +18,32 @@ from .forms import CustomUserCreationForm
16 18
 
17 19
 @login_required
18 20
 def profile(request):
19
-	return render(request, "profile/profile.html", {})
21
+	pwForm = None
22
+
23
+	if request.method == "POST":
24
+		if request.POST.get("submit", None) == "pwchange":
25
+			pwForm = PasswordChangeForm(user=request.user, data=request.POST)
26
+			if pwForm.is_valid():
27
+				pwForm.save()
28
+				auth_login(request, pwForm.user)
29
+				messages.success(request, "Password changed")
30
+
31
+				return HttpResponseRedirect(reverse("profile"))
32
+
33
+	if not pwForm:
34
+		pwForm = PasswordChangeForm(user=request.user)
35
+
36
+	return render(request, "registration/profile.html", {'pwForm': pwForm})
20 37
 
21 38
 
22 39
 @login_required
23 40
 def dashboard(request):
24 41
 	mnts = request.user.maintainer_set.all()
25
-	ownMnts = request.user.maintainer_set.filter(rir=False, lir=False).all()
26
-	asns = ASNumber.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts))
27
-	inetnums = InetNum.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts))
28
-	domains = Domain.objects.filter(mnt_by__in=mnts)
29
-	rrequests = Request.objects.filter((Q(provider__in=mnts) | Q(applicant__in=mnts)) & Q(status=Request.STATE_OPEN))
42
+	ownMnts = request.user.maintainer_set.filter(rir=False, lir=False).all().distinct()
43
+	asns = ASNumber.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts)).distinct()
44
+	inetnums = InetNum.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts)).distinct()
45
+	domains = Domain.objects.filter(mnt_by__in=mnts).distinct()
46
+	rrequests = Request.objects.filter((Q(provider__in=mnts) | Q(applicant__in=mnts)) & Q(status=Request.STATE_OPEN)).distinct()
30 47
 
31 48
 	return render(request, "dncore/dashboard.html", {"asns": asns, "inetnums": inetnums, "domains": domains, 'rrequests': rrequests})
32 49
 

+ 2
- 2
templates/base.html View File

@@ -45,11 +45,11 @@
45 45
         <div id="navbar" class="navbar-collapse collapse">
46 46
           <ul class="nav navbar-nav">
47 47
 {% if user.is_authenticated %}
48
-            <li{% if request.resolver_match.url_name == 'dashboard' %} class="active"{%endif%}><a href="{% url "dashboard" %}">Dashboard</a></li>
48
+            <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>
49 49
 {% else %}
50 50
             <li{% if request.resolver_match.url_name == 'index' %} class="active"{%endif%}><a href="{% url "index" %}">Home</a></li>
51 51
 {% endif %}
52
-            <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>
52
+            <li{% if request.resolver_match.url_name == 'search' %} class="active"{%endif%}><a href="{% url "whoisdb:search" %}">Search</a></li>
53 53
 			<li class="dropdown{% if request.resolver_match.url_name == 'whoisdb' %} active{%endif%}">
54 54
 				<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Whois DB <span class="caret"></span></a>
55 55
 				<ul class="dropdown-menu">

+ 2
- 2
templates/dncore/dashboard.html View File

@@ -60,7 +60,7 @@
60 60
 					{% endfor %}
61 61
 					</table>
62 62
 				{% else %}
63
-					<p>You don't have any domains</p>
63
+					<p>You don't have any ip networks</p>
64 64
 				{% endif %}
65 65
 
66 66
 
@@ -83,7 +83,7 @@
83 83
 					{% endfor %}
84 84
 					</table>
85 85
 				{% else %}
86
-					<p>You don't have any open resource requests</p>
86
+					<p>You don't have any domains</p>
87 87
 				{% endif %}
88 88
 			</div>
89 89
 		</div>

+ 3
- 2
templates/registration/profile.html View File

@@ -9,8 +9,9 @@
9 9
 			<div class="panel-heading">User Info</div>
10 10
 			<div class="panel-body">
11 11
 				<div class="form-group">
12
-					<label class="control-label">User <span class="glyphicon glyphicon-ok-sign text-success"></span></label>
12
+					<label class="control-label">User</label>
13 13
 					<p class="form-control-static">{{ user }}</p>
14
+
14 15
 				</div>
15 16
 			</div>
16 17
 		</div>
@@ -19,7 +20,7 @@
19 20
 		<div class="panel panel-default">
20 21
 			<div class="panel-heading">Change Password</div>
21 22
 			<div class="panel-body">
22
-				<form method="POST" action="{% url "profile" %}">
23
+				<form method="POST" action="{% url "user:profile" %}">
23 24
 					{% csrf_token %}
24 25
 					{{ pwForm|crispy }}
25 26
 					<button type="submit" class="btn btn-primary" name="submit" value="pwchange">Change Password</button>

+ 23
- 4
whoisdb/helpers.py View File

@@ -1,6 +1,8 @@
1 1
 import whoisdb.models
2 2
 import domains.models
3 3
 
4
+from django.db.models import F
5
+
4 6
 import ipaddress
5 7
 import re
6 8
 
@@ -73,17 +75,34 @@ def findInDatabase(rawValue):
73 75
 		pass
74 76
 
75 77
 	if value:
76
-		# TODO FIXME: find smallest matching network
77
-		obj = whoisdb.models.InetNum.objects.filter(address=str(value))
78
-		results.extend(obj)
78
+		# NOTE: this is only for "small subnets", we could increase this...
79
+		baseaddr = None
80
+		if value.version == 4:
81
+			basenet = ipaddress.ip_network("%s/24" % value, strict=False)
82
+			baseaddr = ".".join(str(basenet).split(".")[0:3]) + "."
83
+		else:
84
+			basenet = ipaddress.ip_network("%s/56" % value.exploded, strict=False)
85
+			baseaddr = ":".join(str(basenet).split(":")[0:4])[-2]
86
+
87
+		nets = whoisdb.models.InetNum.objects.filter(address__startswith=baseaddr).order_by("-netmask")
88
+		for net in nets:
89
+			if value in net.getNetwork():
90
+				results.append(net)
91
+				break
79 92
 
80 93
 	# asnumber?
81 94
 	m = re.match("^(?:AS)?(\d+)$", rawValue)
82 95
 	if m:
83 96
 		# asnumber!
84
-		obj = whoisdb.models.ASNumber(number=int(m.group(1)))
97
+		num = int(m.group(1))
98
+		obj = whoisdb.models.ASNumber.objects.filter(number=num)
85 99
 		results.extend(obj)
86 100
 
101
+		# find a matching block
102
+		blocks = whoisdb.models.ASBlock.objects.filter(asBegin__lte=num, asEnd__gte=num).annotate(size=F('asEnd')-F('asBegin')).order_by('size')
103
+		if blocks.count() > 0:
104
+			results.append(blocks[0])
105
+
87 106
 	# asblocks? smallest asblock containing the range
88 107
 	# WHEN anotation foo... could also be done in asnumber match
89 108
 	# also look for number - number queries?

Loading…
Cancel
Save