service updater host configuration: added user interface

this is the ui USERS need to configure sending updates to an ALREADY CONFIGURED service.

there is no UI yet for creating a new service, the ADMIN has to use django admin for that.
This commit is contained in:
Thomas Waldmann 2013-11-29 10:43:18 +01:00
parent 2aeb2a61f8
commit d9e9c66319
6 changed files with 208 additions and 4 deletions

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from django import forms
from .models import Host, Domain
from .models import Host, Domain, ServiceUpdaterHostConfig
class CreateHostForm(forms.ModelForm):
@ -34,3 +34,20 @@ class EditDomainForm(forms.ModelForm):
model = Domain
fields = ['comment', 'nameserver_ip', 'public', 'available',
'nameserver_update_algorithm', 'nameserver_update_secret']
class CreateUpdaterHostConfigForm(forms.ModelForm):
class Meta(object):
model = ServiceUpdaterHostConfig
fields = ['service', 'hostname', 'name', 'password',
'give_ipv4', 'give_ipv6', 'comment']
widgets = {
'hostname': forms.widgets.TextInput(attrs=dict(autofocus=None)),
}
class EditUpdaterHostConfigForm(forms.ModelForm):
class Meta(object):
model = ServiceUpdaterHostConfig
fields = ['hostname', 'comment', 'name', 'password',
'give_ipv4', 'give_ipv6']

View File

@ -12,6 +12,11 @@
{{ form|bootstrap }}
<button type="submit" class="btn btn-primary">Update</button>
</form>
<h3>Update other Services</h3>
<p>We can send updates to other services when we receive an update from you.</p>
<form action="{% url 'updater_hostconfig_overview' host.pk %}" method="get">
<button type="submit" class="btn btn-primary">Configure Updaters</button>
</form>
</div>
<div class="col-lg-4">
<h3>Show Configurations</h3>

View File

@ -0,0 +1,38 @@
{% extends "base.html" %}
{% load bootstrap %}
{% block content %}
<div class="row">
<h3>{{ object.hostname }} ({{ object.service.name }}) <br><small><a href="{% url 'updater_hostconfig_overview' object.host.pk %}"><i class="fa fa-angle-double-left"></i> back to overview</a></small></h3>
<div class="col-lg-6">
<h3>Edit Updater Configuration</h3>
<form method="post" action="">
{% csrf_token %}
{{ form|bootstrap }}
<button type="submit" class="btn btn-primary">Update</button>
</form>
<h3>Delete Updater Configuration</h3>
<p>
Deleting a updater configuration is not undoable. If you need it back, you'll have to add it again.
</p>
<form method="get" action="{% url 'delete_updater_hostconfig' object.pk %}">
<button type="submit" class="btn btn-primary">Delete</button>
</form>
</div>
<div class="col-lg-6">
<div class="well well-sm">
<h3>Help</h3>
<p>Here you can edit the configuration of the "{{ object.service.name }}" updater.
</p>
<p>
The values you need here are the same ones as you would usually enter in your router
or update client.
</p>
<p>
You get these values after registering with the "{{ object.service.name }}" service
and (likely) configuring that service to accept updates.
</p>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,55 @@
{% extends "base.html" %}
{% load bootstrap %}
{% block content %}
<div class="row">
<div class="col-lg-12">
<h3>Your updater configurations for other services</h3>
<table class="table">
<thead>
<tr>
<th>Service</th>
<th>Host</th>
<th>give IPv4</th>
<th>give IPv6</th>
<th>Comment</th>
</tr>
</thead>
{% for uc in updater_configs %}
<tr>
<td>{{ uc.service.name }} (SSL: {{ uc.service.secure|yesno }})</td>
<td><a href="{% url 'updater_hostconfig' uc.pk %}">{{ uc.hostname }}</a></td>
<td>{{ uc.give_ipv4|yesno }}</td>
<td>{{ uc.give_ipv6|yesno }}</td>
<td>{{ uc.comment }}</td>
</tr>
{% empty %}
<tr>No other services to update yet.</tr>
{% endfor %}
</table>
</div>
</div>
<hr>
<div class="row">
<div class="col-lg-6">
<div class="well well-sm">
<h3>Create a new updater configuration</h3>
<form method="post" action="">
{% csrf_token %}
{{ form|bootstrap }}
<button type="submit" class="btn btn-primary">Create</button>
</form>
</div>
</div>
<div class="col-lg-6">
<div class="well well-sm">
<h3>Help</h3>
<p>Here you can add new configurations for 3rd party services you like to get updated.
</p>
<p>We will send an update to them each time you update your host with us.
</p>
</div>
</div>
</div>
{% endblock %}

View File

@ -3,7 +3,8 @@ 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,
UpdaterHostConfigOverviewView, UpdaterHostConfigView, DeleteUpdaterHostConfigView)
from ..api.views import (
myip_view, DetectIpView, AjaxGetIps, NicUpdateView, AuthorizedNicUpdateView)
@ -23,6 +24,11 @@ urlpatterns = patterns(
url(r'^host/(?P<pk>\d+)/delete/$', DeleteHostView.as_view(), name='delete_host'),
url(r'^domain_overview/$', DomainOverviewView.as_view(), name='domain_overview'),
url(r'^domain/(?P<pk>\d+)/delete/$', DeleteDomainView.as_view(), name='delete_domain'),
url(r'^updater_hostconfig_overview/(?P<pk>\d+)/$', UpdaterHostConfigOverviewView.as_view(),
name='updater_hostconfig_overview'),
url(r'^updater_hostconfig/(?P<pk>\d+)/$', UpdaterHostConfigView.as_view(), name='updater_hostconfig'),
url(r'^updater_hostconfig/(?P<pk>\d+)/delete/$', DeleteUpdaterHostConfigView.as_view(),
name='delete_updater_hostconfig'),
# internal use by the web ui
url(r'^detectip/(?P<sessionid>\w+)/$', DetectIpView.as_view(), name='detectip'),
url(r'^ajax_get_ips/$', AjaxGetIps.as_view(), name="ajax_get_ips"),

View File

@ -16,8 +16,9 @@ from django.utils.timezone import now
import dnstools
from .forms import CreateHostForm, EditHostForm, CreateDomainForm, EditDomainForm
from .models import Host, Domain
from .forms import (CreateHostForm, EditHostForm, CreateDomainForm, EditDomainForm,
CreateUpdaterHostConfigForm, EditUpdaterHostConfigForm)
from .models import Host, Domain, ServiceUpdaterHostConfig
class GenerateSecretView(UpdateView):
@ -317,6 +318,88 @@ class DeleteDomainView(DeleteView):
return context
class UpdaterHostConfigOverviewView(CreateView):
model = ServiceUpdaterHostConfig
template_name = "main/updater_hostconfig_overview.html"
form_class = CreateUpdaterHostConfigForm
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
self.__host_pk = kwargs.pop('pk', None)
return super(UpdaterHostConfigOverviewView, self).dispatch(*args, **kwargs)
def get_success_url(self):
return reverse('updater_hostconfig_overview', args=(self.__host_pk,))
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.host = Host(pk=self.__host_pk)
self.object.created_by = self.request.user
self.object.save()
messages.add_message(self.request, messages.SUCCESS, 'Service Updater Host Configuration added.')
return HttpResponseRedirect(self.get_success_url())
def get_context_data(self, *args, **kwargs):
context = super(
UpdaterHostConfigOverviewView, self).get_context_data(*args, **kwargs)
context['updater_configs'] = ServiceUpdaterHostConfig.objects.filter(
host=self.__host_pk)
return context
class UpdaterHostConfigView(UpdateView):
model = ServiceUpdaterHostConfig
template_name = "main/updater_hostconfig.html"
form_class = EditUpdaterHostConfigForm
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(UpdaterHostConfigView, self).dispatch(*args, **kwargs)
def get_success_url(self):
host_pk = self.object.host.pk
return reverse('updater_hostconfig_overview', args=(host_pk,))
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.save()
messages.add_message(self.request, messages.SUCCESS, 'Service Updater Host Configuration updated.')
return HttpResponseRedirect(self.get_success_url())
def get_object(self, *args, **kwargs):
obj = super(UpdaterHostConfigView, self).get_object(*args, **kwargs)
if obj.created_by != self.request.user:
raise PermissionDenied() # or Http404
return obj
def get_context_data(self, *args, **kwargs):
context = super(UpdaterHostConfigView, self).get_context_data(*args, **kwargs)
return context
class DeleteUpdaterHostConfigView(DeleteView):
model = ServiceUpdaterHostConfig
template_name = "main/delete_object.html"
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(DeleteUpdaterHostConfigView, self).dispatch(*args, **kwargs)
def get_object(self, *args, **kwargs):
obj = super(DeleteUpdaterHostConfigView, self).get_object(*args, **kwargs)
if obj.created_by != self.request.user:
raise PermissionDenied() # or Http404
return obj
def get_success_url(self):
host_pk = self.object.host.pk
return reverse('updater_hostconfig_overview', args=(host_pk,))
def get_context_data(self, *args, **kwargs):
context = super(DeleteUpdaterHostConfigView, self).get_context_data(*args, **kwargs)
return context
class RobotsTxtView(View):
"""
Dynamically serve robots.txt content.