From 04602c53a66cec613ca01a8335e5bf16bff31ad4 Mon Sep 17 00:00:00 2001 From: Fabian Faessler Date: Sat, 28 Sep 2013 19:01:40 +0200 Subject: [PATCH] get ipv4 and ipv6 adr from session --- nsupdate/api/views.py | 10 +++++++++- nsupdate/main/templates/main/overview.html | 19 +++++-------------- nsupdate/main/urls.py | 3 ++- nsupdate/main/views.py | 1 + 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/nsupdate/api/views.py b/nsupdate/api/views.py index 7431613..7ae153d 100644 --- a/nsupdate/api/views.py +++ b/nsupdate/api/views.py @@ -3,4 +3,12 @@ from django.http import HttpResponse from django.conf import settings def MyIpView(request): - return HttpResponse(request.META['REMOTE_ADDR'], content_type="text/plain") \ No newline at end of file + return HttpResponse(request.META['REMOTE_ADDR'], content_type="text/plain") + +def UpdateIpView(request): + ip = request.META['REMOTE_ADDR'] + if ':' in ip: + request.session['ipv6'] = request.META['REMOTE_ADDR'] + if '.' in ip: + request.session['ipv4'] = request.META['REMOTE_ADDR'] + return HttpResponse('OK', content_type="text/plain") \ No newline at end of file diff --git a/nsupdate/main/templates/main/overview.html b/nsupdate/main/templates/main/overview.html index 03b2330..a85f36b 100644 --- a/nsupdate/main/templates/main/overview.html +++ b/nsupdate/main/templates/main/overview.html @@ -6,19 +6,10 @@

Ajax request to retrieve the ipv4/ipv6 remote address. The URL www.*.nsupdate.info is used for the call, so this will fail for the dev server. TODO: dev environment

- IPv4:
- IPv6: - - + IPv4:
+ IPv6: + + + {% endblock %} \ No newline at end of file diff --git a/nsupdate/main/urls.py b/nsupdate/main/urls.py index fb71d5c..a56707f 100644 --- a/nsupdate/main/urls.py +++ b/nsupdate/main/urls.py @@ -3,11 +3,12 @@ from main.views import ( HomeView, OverviewView ) from api.views import ( - MyIpView, + MyIpView, UpdateIpView ) urlpatterns = patterns('', url(r'^$', HomeView.as_view(), name="home"), url(r'^overview/', OverviewView.as_view(), name="overview"), url(r'^myip$', MyIpView), + url(r'^updateip$', UpdateIpView), ) diff --git a/nsupdate/main/views.py b/nsupdate/main/views.py index 5a7975f..32e8b11 100644 --- a/nsupdate/main/views.py +++ b/nsupdate/main/views.py @@ -20,5 +20,6 @@ class OverviewView(TemplateView): context['nav_overview'] = True context['WWW_IPV4_HOST'] = settings.WWW_IPV4_HOST context['WWW_IPV6_HOST'] = settings.WWW_IPV6_HOST + context['session'] = self.request.session return context