get ipv4 and ipv6 adr from session
This commit is contained in:
parent
bde430646a
commit
04602c53a6
@ -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")
|
||||
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")
|
@ -6,19 +6,10 @@
|
||||
<p>
|
||||
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
|
||||
</p>
|
||||
IPv4: <input type='text' class="form-control ipv4adr" placeholder="loading ip..."> </br >
|
||||
IPv6: <input type='text' class="form-control ipv6adr" placeholder="loading ip...">
|
||||
|
||||
<script>
|
||||
|
||||
$.get('//{{ WWW_IPV4_HOST }}/myip','',function(res){
|
||||
alert('Your name is '+res);
|
||||
});
|
||||
|
||||
$.get('//{{ WWW_IPV6_HOST }}/myip','',function(res){
|
||||
alert('Your name is '+res);
|
||||
});
|
||||
|
||||
</script>
|
||||
IPv4: <input type='text' class="form-control ipv4adr" placeholder="loading ip..." value="{{session.ipv4}}"> </br >
|
||||
IPv6: <input type='text' class="form-control ipv6adr" placeholder="loading ip..." value="{{session.ipv6}}">
|
||||
|
||||
<img src="//{{ WWW_IPV4_HOST }}/updateip" />
|
||||
<img src="//{{ WWW_IPV6_HOST }}/updateip" />
|
||||
|
||||
{% endblock %}
|
@ -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),
|
||||
)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user