Merge branch 'master' of github.com:asmaps/nsupdate.info
This commit is contained in:
commit
dab77b9074
27
nsupdate/main/_tests/test_dnstools.py
Normal file
27
nsupdate/main/_tests/test_dnstools.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
"""
|
||||||
|
Tests for dnstools module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from nsupdate.main.dnstools import (query_ns, NONEXISTING_HOST, WWW_HOST, WWW_IPV4_HOST, WWW_IPV4_IP,
|
||||||
|
WWW_IPV6_HOST, WWW_IPV6_IP, )
|
||||||
|
|
||||||
|
from dns.resolver import NXDOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
class Tests(object):
|
||||||
|
def test_queries_ok(self):
|
||||||
|
"""
|
||||||
|
check some simple dns lookups
|
||||||
|
"""
|
||||||
|
assert query_ns(WWW_IPV4_HOST, 'A') == WWW_IPV4_IP # v4 ONLY
|
||||||
|
assert query_ns(WWW_IPV6_HOST, 'AAAA') == WWW_IPV6_IP # v6 ONLY
|
||||||
|
assert query_ns(WWW_HOST, 'A') == WWW_IPV4_IP # v4 and v6, query v4
|
||||||
|
assert query_ns(WWW_HOST, 'AAAA') == WWW_IPV6_IP # v4 and v6, query v6
|
||||||
|
|
||||||
|
def test_queries_failing(self):
|
||||||
|
with pytest.raises(NXDOMAIN):
|
||||||
|
query_ns(NONEXISTING_HOST, 'A')
|
||||||
|
with pytest.raises(NXDOMAIN):
|
||||||
|
query_ns(NONEXISTING_HOST, 'AAAA')
|
34
nsupdate/main/dnstools.py
Normal file
34
nsupdate/main/dnstools.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
"""
|
||||||
|
Misc. DNS related code: query, dynamic update, etc.
|
||||||
|
"""
|
||||||
|
|
||||||
|
SERVER = '85.10.192.104' # ns1.thinkmo.de (master / dynamic upd server for nsupdate.info)
|
||||||
|
BASEDOMAIN = 'nsupdate.info'
|
||||||
|
|
||||||
|
NONEXISTING_HOST = 'nonexisting.' + BASEDOMAIN
|
||||||
|
WWW_HOST = 'www.' + BASEDOMAIN
|
||||||
|
WWW_IPV4_HOST = 'www.ipv4.' + BASEDOMAIN
|
||||||
|
WWW_IPV6_HOST = 'www.ipv6.' + BASEDOMAIN
|
||||||
|
WWW_IPV4_IP = '178.32.221.14'
|
||||||
|
WWW_IPV6_IP = '2001:41d0:8:e00e::1'
|
||||||
|
|
||||||
|
import dns.name
|
||||||
|
import dns.resolver
|
||||||
|
|
||||||
|
def query_ns(qname, rdtype):
|
||||||
|
"""
|
||||||
|
query a dns name from our master server
|
||||||
|
|
||||||
|
:param qname: the query name
|
||||||
|
:type qname: dns.name.Name object or str
|
||||||
|
:param rdtype: the query type
|
||||||
|
:type rdtype: int or str
|
||||||
|
:return: IP (as str)
|
||||||
|
"""
|
||||||
|
resolver = dns.resolver.Resolver(configure=False)
|
||||||
|
# we do not configure it from resolv.conf, but patch in the values we
|
||||||
|
# want into the documented attributes:
|
||||||
|
resolver.nameservers = [SERVER, ]
|
||||||
|
resolver.search = [dns.name.from_text(BASEDOMAIN), ]
|
||||||
|
answer = resolver.query(qname, rdtype)
|
||||||
|
return str(list(answer)[0])
|
@ -1,6 +1,8 @@
|
|||||||
from django.conf.urls import patterns, include, url
|
from django.conf.urls import patterns, include, url
|
||||||
from main.views import HomeView
|
from main.views import HomeView, MyIpView, OverviewView
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^$', HomeView.as_view(), name="home"),
|
url(r'^$', HomeView.as_view(), name="home"),
|
||||||
|
url(r'^overview/', OverviewView.as_view(), name="overview"),
|
||||||
|
url(r'^myip/', MyIpView)
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
from django.http import HttpResponse
|
||||||
|
import json
|
||||||
|
|
||||||
class HomeView(TemplateView):
|
class HomeView(TemplateView):
|
||||||
template_name = "base.html"
|
template_name = "base.html"
|
||||||
@ -9,3 +10,15 @@ class HomeView(TemplateView):
|
|||||||
context = super(HomeView, self).get_context_data(*args, **kwargs)
|
context = super(HomeView, self).get_context_data(*args, **kwargs)
|
||||||
context['nav_home'] = True
|
context['nav_home'] = True
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
class OverviewView(TemplateView):
|
||||||
|
template_name = "overview.html"
|
||||||
|
|
||||||
|
def get_context_data(self, *args, **kwargs):
|
||||||
|
context = super(OverviewView, self).get_context_data(*args, **kwargs)
|
||||||
|
context['nav_overview'] = True
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
def MyIpView(request):
|
||||||
|
return HttpResponse(json.dumps({'ip':request.META['REMOTE_ADDR']}), content_type="application/json")
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
|
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link href="{% static 'css/nsupdate.css' %}" rel="stylesheet">
|
<link href="{% static 'css/nsupdate.css' %}" rel="stylesheet">
|
||||||
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -27,6 +28,7 @@
|
|||||||
<div class="collapse navbar-collapse">
|
<div class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li{% if nav_home %} class="active"{% endif %}><a href="{% url 'home' %}">Home</a></li>
|
<li{% if nav_home %} class="active"{% endif %}><a href="{% url 'home' %}">Home</a></li>
|
||||||
|
<li{% if nav_overview %} class="active"{% endif %}><a href="{% url 'overview' %}">Overview</a></li>
|
||||||
<li{% if nav_about %} class="active"{% endif %}><a href="#about">About</a></li>
|
<li{% if nav_about %} class="active"{% endif %}><a href="#about">About</a></li>
|
||||||
<li{% if nav_contact %} class="active"{% endif %}><a href="#contact">Contact</a></li>
|
<li{% if nav_contact %} class="active"{% endif %}><a href="#contact">Contact</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
29
nsupdate/nsupdate/templates/overview.html
Normal file
29
nsupdate/nsupdate/templates/overview.html
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
getIp = function(protocol) {
|
||||||
|
$.get("http://www.ip"+protocol+".nsupdate.info/myip", function(raw_data){
|
||||||
|
json_data = JSON.parse(raw_data)
|
||||||
|
$(".ip"+protocol+"adr").val(json_data.ip);
|
||||||
|
}).fail(function() {
|
||||||
|
$(".ip"+protocol+"adr").val("no ip"+protocol+" address found");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
getIp('v4');
|
||||||
|
getIp('v6');
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>Overview</h1>
|
||||||
|
<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...">
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user