view with js based updater - thanks for 1v3ry for helping
This commit is contained in:
parent
737102cef0
commit
de973353cf
53
nsupdate/main/templates/main/update.html
Normal file
53
nsupdate/main/templates/main/update.html
Normal file
@ -0,0 +1,53 @@
|
||||
{% extends "base.html" %}
|
||||
{% load bootstrap %}
|
||||
|
||||
{% block content %}
|
||||
<div class="jumbotron">
|
||||
<h2>Browser-based Updater</h2>
|
||||
<p>
|
||||
Host {{ hostname }} (pw {{ secret }}) will get automatically updated as long as you keep this window open.
|
||||
</p>
|
||||
<noscript>
|
||||
<p class="text-danger">
|
||||
The browser based updater only works if javascript is enabled.
|
||||
</p>
|
||||
</noscript>
|
||||
<h2>Updater Status</h2>
|
||||
<dl>
|
||||
<dt>Last response:</dt><dd><span id="response"></span></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
// Thanks to 1v3ry for helping with the js code!
|
||||
var last_ip = '';
|
||||
|
||||
function checkIP() {
|
||||
$.get("{% url 'myip' %}")
|
||||
.done(function( data ) {
|
||||
ip = data;
|
||||
if(ip != last_ip) {
|
||||
$.ajax({
|
||||
url: "{% url 'nic_update' %}",
|
||||
username: "{{ hostname }}",
|
||||
password: "{{ secret }}"
|
||||
})
|
||||
.done(function( data ) {
|
||||
$('#response').text(data);
|
||||
last_ip = ip;
|
||||
})
|
||||
.fail(function (data) {
|
||||
$('#response').text('update failed');
|
||||
});
|
||||
}
|
||||
})
|
||||
.fail(function( data ) {
|
||||
$('#response').text('myip failed');
|
||||
});
|
||||
setTimeout('checkIP', 300000); // repeat in N ms
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
checkIP();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
@ -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<pk>\d+)/$', HostView.as_view(), name='host_view'),
|
||||
url(r'^domain/(?P<pk>\d+)/$', DomainView.as_view(), name='domain_view'),
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user