95 lines
3.8 KiB
HTML

{% extends "base.html" %}
{% load bootstrap %}
{% block content %}
<div class="jumbotron">
<h2>Browser-based Updater</h2>
<p>
Host {{ hostname }} 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>My IP:</dt>
<dd><span id="myip"></span> (<span id="myip_timestamp"></span>)</dd>
<dt>Last update response:</dt>
<dd><span id="response"></span> (<span id="response_timestamp"></span>)</dd>
</dl>
</div>
<script type="text/javascript">
// Thanks to 1v3ry for helping with the js code!
var last_ip = '';
function format_dt(dt) {
// return a somehow ISO-like formatted local date / time string,
// but without timezone, "T", "Z", milliseconds or other stuff.
function pad(number) {
return number <= 9 ? '0' + number : number;
}
return (
dt.getFullYear() + '-' + pad(dt.getMonth() + 1) + '-' + pad(dt.getDate()) +
' ' +
pad(dt.getHours()) + ':' + pad(dt.getMinutes()) + ':' + pad(dt.getSeconds())
);
}
function now_str() {
var dt = new Date();
return format_dt(dt);
}
function checkIP() {
$.get("{% url 'myip' %}")
.done(function( data ) {
var ip = data;
$('#myip').text(ip);
$('#myip_timestamp').text(now_str());
if(ip != last_ip) {
$.ajax({
url: "{% url 'nic_update' %}",
username: "{{ hostname }}",
password: "{{ secret }}"
})
.done(function( data ) {
var msg;
last_ip = ip;
response = data.split(" ");
switch(response[0])
{
case "good": msg = "Success: IP address was updated"; break;
case "nochg": msg = "Warning: IP address didn't change"; break;
case "dnserr": msg = "Error: The update request resulted in a DNS error"; break;
case "nohost": msg = "Error: The host you specified does not exist"; break;
case "abuse": msg = "Error: Update rejected as your host is flagged for abuse"; break;
case "badauth": msg = "Error: Wrong user name (host FQDN) or password (update secret)"; break;
case "badagent": msg = "Error: Update rejected as your user agent is blacklisted"; break;
case "notfqdn": msg = "Error: Your user name is not the FQDN of your host"; break;
case "911": msg = "Error: There is a problem or maintenance at the DNS update service."; break;
default: msg = "Error:"; break;
}
$('#response').text(msg + " [" + data + "].");
$('#response_timestamp').text(now_str());
})
.fail(function( data ) {
$('#response').text('Error: Could not connect to the DNS update service - will retry soon...');
$('#response_timestamp').text(now_str());
});
}
})
.fail(function( data ) {
$('#response').text('Error: Could not determine IP address - will retry soon...');
$('#response_timestamp').text(now_str());
});
}
$(document).ready(function() {
checkIP(); // run immediately ...
setInterval(checkIP, 300000); // ... then repeat every N ms
});
</script>
{% endblock %}