From c6bdd34feebfb2cf707ad7d59e778c69521404db Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 31 Aug 2014 01:03:19 +0200 Subject: [PATCH] split off add host / add domain view from hosts overview / domains overview --- nsupdate/main/templates/main/domain_add.html | 33 +++++++++++ .../main/templates/main/domain_overview.html | 35 ++--------- nsupdate/main/templates/main/host_add.html | 48 +++++++++++++++ .../main/templates/main/host_overview.html | 50 ++-------------- nsupdate/main/urls.py | 6 +- nsupdate/main/views.py | 59 ++++++++++++++----- nsupdate/templates/base.html | 2 +- 7 files changed, 139 insertions(+), 94 deletions(-) create mode 100644 nsupdate/main/templates/main/domain_add.html create mode 100644 nsupdate/main/templates/main/host_add.html diff --git a/nsupdate/main/templates/main/domain_add.html b/nsupdate/main/templates/main/domain_add.html new file mode 100644 index 0000000..447785e --- /dev/null +++ b/nsupdate/main/templates/main/domain_add.html @@ -0,0 +1,33 @@ +{% extends "base.html" %} +{% load i18n %}{% load bootstrap %} + +{% block content %} +
+
+
+

{% trans "Add a new Domain" %}

+
+ {% csrf_token %} + {{ form|bootstrap }} + +
+
+
+
+
+

{% trans "Help" %}

+

+ {% blocktrans %}Here you can add new domains (zones) which you control (and this is only useful if you + have some own zone which you can update automatically).{% endblocktrans %} +

+

+ {% blocktrans %}You need to be able to configure the primary master nameserver of the zone so it accepts + dynamic updates (via RFC 2136 "dynamic update" protocol) if the correct update secret is presented.{% endblocktrans %} +

+

+ {% trans "We'll show you configuration examples after you add a domain." %} +

+
+
+
+{% endblock %} diff --git a/nsupdate/main/templates/main/domain_overview.html b/nsupdate/main/templates/main/domain_overview.html index 9aa46f1..af1e052 100644 --- a/nsupdate/main/templates/main/domain_overview.html +++ b/nsupdate/main/templates/main/domain_overview.html @@ -4,7 +4,10 @@ {% block content %}
-

{% trans "Domains (yours first, then public)" %}

+

+ {% trans "Domains (yours first, then public)" %} + {% trans "Add Domain" %} +

@@ -40,34 +43,4 @@
-
- -
-
-
-

{% trans "Add a new Domain" %}

-
- {% csrf_token %} - {{ form|bootstrap }} - -
-
-
-
-
-

{% trans "Help" %}

-

- {% blocktrans %}Here you can add new domains (zones) which you control (and this is only useful if you - have some own zone which you can update automatically).{% endblocktrans %} -

-

- {% blocktrans %}You need to be able to configure the primary master nameserver of the zone so it accepts - dynamic updates (via RFC 2136 "dynamic update" protocol) if the correct update secret is presented.{% endblocktrans %} -

-

- {% trans "We'll show you configuration examples after you add a domain." %} -

-
-
-
{% endblock %} diff --git a/nsupdate/main/templates/main/host_add.html b/nsupdate/main/templates/main/host_add.html new file mode 100644 index 0000000..b0ec756 --- /dev/null +++ b/nsupdate/main/templates/main/host_add.html @@ -0,0 +1,48 @@ +{% extends "base.html" %} +{% load i18n %}{% load bootstrap %} + +{% block content %} +
+
+
+

{% trans "Create a new Host" %}

+
+ {% csrf_token %} + {{ form|bootstrap }} + +
+
+
+
+
+

{% trans "Help" %}

+

{% trans "Here you can add new hosts (like routers, PCs, servers, ...)." %} +

+

{% blocktrans %}You need to be able to configure one of your machines so it sends dyndns2 compatible + updates to us when your IP changes. Routers usually have some builtin software that does + this, but you can also use some software on another system (like a PC or server).{% endblocktrans %} +

+

+ {% blocktrans %}Just make sure your update client either is customizable well enough or has specific + support for our service.{% endblocktrans %} +

+

+ {% trans "We'll show you configuration examples after you add a host." %} +

+
+
+

{% trans "Your current IP(s) + reverse DNS:" %}

+

+ IPv4: {{ request.session.ipv4 }} +
+ rDNS: {{ request.session.ipv4_rdns }} +

+

+ IPv6: {{ request.session.ipv6 }} +
+ rDNS: {{ request.session.ipv6_rdns }} +

+
+
+
+{% endblock %} diff --git a/nsupdate/main/templates/main/host_overview.html b/nsupdate/main/templates/main/host_overview.html index 7eab7c1..5190311 100644 --- a/nsupdate/main/templates/main/host_overview.html +++ b/nsupdate/main/templates/main/host_overview.html @@ -4,7 +4,10 @@ {% block content %}
-

{% trans "Your Hosts" %}

+

+ {% trans "Your Hosts" %} + {% trans "Add Host" %} +

@@ -58,49 +61,4 @@
-
- -
-
-
-

{% trans "Create a new Host" %}

-
- {% csrf_token %} - {{ form|bootstrap }} - -
-
-
-
-
-

{% trans "Help" %}

-

{% trans "Here you can add new hosts (like routers, PCs, servers, ...)." %} -

-

{% blocktrans %}You need to be able to configure one of your machines so it sends dyndns2 compatible - updates to us when your IP changes. Routers usually have some builtin software that does - this, but you can also use some software on another system (like a PC or server).{% endblocktrans %} -

-

- {% blocktrans %}Just make sure your update client either is customizable well enough or has specific - support for our service.{% endblocktrans %} -

-

- {% trans "We'll show you configuration examples after you add a host." %} -

-
-
-

{% trans "Your current IP(s) + reverse DNS:" %}

-

- IPv4: {{ request.session.ipv4 }} -
- rDNS: {{ request.session.ipv4_rdns }} -

-

- IPv6: {{ request.session.ipv6 }} -
- rDNS: {{ request.session.ipv6_rdns }} -

-
-
-
{% endblock %} diff --git a/nsupdate/main/urls.py b/nsupdate/main/urls.py index ade4206..b23a369 100644 --- a/nsupdate/main/urls.py +++ b/nsupdate/main/urls.py @@ -6,8 +6,8 @@ from django.conf.urls import patterns, url from django.views.generic import TemplateView from .views import ( - HomeView, OverviewView, HostView, DeleteHostView, AboutView, GenerateSecretView, GenerateNSSecretView, - RobotsTxtView, DomainOverviewView, DomainView, DeleteDomainView, StatusView, JsUpdateView, + HomeView, OverviewView, HostView, AddHostView, DeleteHostView, AboutView, GenerateSecretView, GenerateNSSecretView, + RobotsTxtView, DomainOverviewView, DomainView, AddDomainView, DeleteDomainView, StatusView, JsUpdateView, UpdaterHostConfigOverviewView, UpdaterHostConfigView, DeleteUpdaterHostConfigView, CustomTemplateView) from ..api.views import ( myip_view, DetectIpView, AjaxGetIps, NicUpdateView, AuthorizedNicUpdateView, @@ -27,8 +27,10 @@ urlpatterns = patterns( url(r'^status/$', StatusView.as_view(), name='status'), url(r'^generate_secret/(?P\d+)/$', GenerateSecretView.as_view(), name='generate_secret_view'), url(r'^generate_ns_secret/(?P\d+)/$', GenerateNSSecretView.as_view(), name='generate_ns_secret_view'), + url(r'^host/add/$', AddHostView.as_view(), name='add_host'), url(r'^host/(?P\d+)/delete/$', DeleteHostView.as_view(), name='delete_host'), url(r'^domain_overview/$', DomainOverviewView.as_view(), name='domain_overview'), + url(r'^domain/add/$', AddDomainView.as_view(), name='add_domain'), url(r'^domain/(?P\d+)/delete/$', DeleteDomainView.as_view(), name='delete_domain'), url(r'^updater_hostconfig_overview/(?P\d+)/$', UpdaterHostConfigOverviewView.as_view(), name='updater_hostconfig_overview'), diff --git a/nsupdate/main/views.py b/nsupdate/main/views.py index 45895d6..c2bda8f 100644 --- a/nsupdate/main/views.py +++ b/nsupdate/main/views.py @@ -41,7 +41,7 @@ class GenerateSecretView(UpdateView): def get_context_data(self, *args, **kwargs): context = super(GenerateSecretView, self).get_context_data(*args, **kwargs) - context['nav_overview'] = True + context['nav_host_overview'] = True # generate secret, store it hashed and return the plain secret for the context context['update_secret'] = self.object.generate_secret() context['hosts'] = Host.objects.filter(created_by=self.request.user) @@ -173,20 +173,34 @@ class JsUpdateView(TemplateView): return context -class OverviewView(CreateView): - model = Host +class OverviewView(TemplateView): template_name = "main/host_overview.html" - form_class = CreateHostForm @method_decorator(login_required) def dispatch(self, *args, **kwargs): return super(OverviewView, self).dispatch(*args, **kwargs) + def get_context_data(self, *args, **kwargs): + context = super(OverviewView, self).get_context_data(*args, **kwargs) + context['nav_host_overview'] = True + context['hosts'] = Host.objects.filter(created_by=self.request.user) + return context + + +class AddHostView(CreateView): + template_name = "main/host_add.html" + model = Host + form_class = CreateHostForm + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(AddHostView, self).dispatch(*args, **kwargs) + def get_success_url(self): return reverse('generate_secret_view', args=(self.object.pk,)) def get_form(self, form_class): - form = super(OverviewView, self).get_form(form_class) + form = super(AddHostView, self).get_form(form_class) form.fields['domain'].queryset = Domain.objects.filter( Q(created_by=self.request.user) | Q(public=True)) return form @@ -217,9 +231,8 @@ class OverviewView(CreateView): return HttpResponseRedirect(url) def get_context_data(self, *args, **kwargs): - context = super(OverviewView, self).get_context_data(*args, **kwargs) - context['nav_overview'] = True - context['hosts'] = Host.objects.filter(created_by=self.request.user) + context = super(AddHostView, self).get_context_data(*args, **kwargs) + context['nav_host_overview'] = True return context @@ -249,7 +262,7 @@ class HostView(UpdateView): def get_context_data(self, *args, **kwargs): context = super(HostView, self).get_context_data(*args, **kwargs) - context['nav_overview'] = True + context['nav_host_overview'] = True context['remote_addr'] = self.request.META['REMOTE_ADDR'] context['hosts'] = Host.objects.filter(created_by=self.request.user) return context @@ -274,20 +287,38 @@ class DeleteHostView(DeleteView): def get_context_data(self, *args, **kwargs): context = super(DeleteHostView, self).get_context_data(*args, **kwargs) - context['nav_overview'] = True + context['nav_host_overview'] = True context['hosts'] = Host.objects.filter(created_by=self.request.user) return context -class DomainOverviewView(CreateView): - model = Domain +class DomainOverviewView(TemplateView): template_name = "main/domain_overview.html" - form_class = CreateDomainForm @method_decorator(login_required) def dispatch(self, *args, **kwargs): return super(DomainOverviewView, self).dispatch(*args, **kwargs) + def get_context_data(self, *args, **kwargs): + context = super( + DomainOverviewView, self).get_context_data(*args, **kwargs) + context['nav_domain_overview'] = True + context['your_domains'] = Domain.objects.filter( + created_by=self.request.user) + context['public_domains'] = Domain.objects.filter( + public=True).exclude(created_by=self.request.user) + return context + + +class AddDomainView(CreateView): + template_name = "main/domain_add.html" + model = Domain + form_class = CreateDomainForm + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(AddDomainView, self).dispatch(*args, **kwargs) + def get_success_url(self): return reverse('generate_ns_secret_view', args=(self.object.pk,)) @@ -300,7 +331,7 @@ class DomainOverviewView(CreateView): def get_context_data(self, *args, **kwargs): context = super( - DomainOverviewView, self).get_context_data(*args, **kwargs) + AddDomainView, self).get_context_data(*args, **kwargs) context['nav_domain_overview'] = True context['your_domains'] = Domain.objects.filter( created_by=self.request.user) diff --git a/nsupdate/templates/base.html b/nsupdate/templates/base.html index 29c2b0f..908b04e 100644 --- a/nsupdate/templates/base.html +++ b/nsupdate/templates/base.html @@ -40,7 +40,7 @@ {% trans "Home" %} {% if request.user.is_authenticated %} - + {% trans "Hosts" %}