From de973353cf504b497a2af55cbd9bb792d27c0def Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 6 Dec 2013 13:59:26 +0100 Subject: [PATCH] view with js based updater - thanks for 1v3ry for helping --- nsupdate/main/templates/main/update.html | 53 ++++++++++++++++++++++++ nsupdate/main/urls.py | 3 +- nsupdate/main/views.py | 22 ++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 nsupdate/main/templates/main/update.html diff --git a/nsupdate/main/templates/main/update.html b/nsupdate/main/templates/main/update.html new file mode 100644 index 0000000..76cc085 --- /dev/null +++ b/nsupdate/main/templates/main/update.html @@ -0,0 +1,53 @@ +{% extends "base.html" %} +{% load bootstrap %} + +{% block content %} +
+

Browser-based Updater

+

+ Host {{ hostname }} (pw {{ secret }}) will get automatically updated as long as you keep this window open. +

+ +

Updater Status

+
+
Last response:
+
+
+ +{% endblock %} diff --git a/nsupdate/main/urls.py b/nsupdate/main/urls.py index 2843191..2f7c436 100644 --- a/nsupdate/main/urls.py +++ b/nsupdate/main/urls.py @@ -3,7 +3,7 @@ from django.views.generic import TemplateView from .views import ( HomeView, OverviewView, HostView, DeleteHostView, AboutView, GenerateSecretView, GenerateNSSecretView, - RobotsTxtView, DomainOverviewView, DomainView, DeleteDomainView, StatusView, + RobotsTxtView, DomainOverviewView, DomainView, DeleteDomainView, StatusView, UpdateView, UpdaterHostConfigOverviewView, UpdaterHostConfigView, DeleteUpdaterHostConfigView) from ..api.views import ( myip_view, DetectIpView, AjaxGetIps, NicUpdateView, AuthorizedNicUpdateView) @@ -15,6 +15,7 @@ urlpatterns = patterns( url(r'^$', HomeView.as_view(), name="home"), url(r'^about/$', AboutView.as_view(), name="about"), url(r'^legal/$', TemplateView.as_view(template_name='main/legal.html'), name="legal"), + url(r'^update$', UpdateView.as_view(), name='update'), url(r'^overview/$', OverviewView.as_view(), name='overview'), url(r'^host/(?P\d+)/$', HostView.as_view(), name='host_view'), url(r'^domain/(?P\d+)/$', DomainView.as_view(), name='domain_view'), diff --git a/nsupdate/main/views.py b/nsupdate/main/views.py index 4b01574..cc7d508 100644 --- a/nsupdate/main/views.py +++ b/nsupdate/main/views.py @@ -139,6 +139,28 @@ class StatusView(TemplateView): return context +from nsupdate.api.views import basic_challenge, basic_authenticate + + +class UpdateView(TemplateView): + template_name = "main/update.html" + + def get(self, request, *args, **kwargs): + auth = request.META.get('HTTP_AUTHORIZATION') + if auth is None: + return basic_challenge("authenticate to update DNS", 'badauth') + username, password = basic_authenticate(auth) + self.hostname = username + self.secret = password + return super(UpdateView, self).get(request, *args, **kwargs) + + def get_context_data(self, *args, **kwargs): + context = super(UpdateView, self).get_context_data(*args, **kwargs) + context['hostname'] = self.hostname + context['secret'] = self.secret + return context + + class OverviewView(CreateView): model = Host template_name = "main/overview.html"