js updater: add myip output to status, add timestamps

This commit is contained in:
Thomas Waldmann 2013-12-06 21:15:42 +01:00
parent 915d64b592
commit a58a957b28

View File

@ -5,7 +5,7 @@
<div class="jumbotron"> <div class="jumbotron">
<h2>Browser-based Updater</h2> <h2>Browser-based Updater</h2>
<p> <p>
Host {{ hostname }} (pw {{ secret }}) will get automatically updated as long as you keep this window open. Host {{ hostname }} will get automatically updated as long as you keep this window open.
</p> </p>
<noscript> <noscript>
<p class="text-danger"> <p class="text-danger">
@ -14,7 +14,10 @@
</noscript> </noscript>
<h2>Updater Status</h2> <h2>Updater Status</h2>
<dl> <dl>
<dt>Last response:</dt><dd><span id="response"></span></dd> <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> </dl>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
@ -25,6 +28,8 @@
$.get("{% url 'myip' %}") $.get("{% url 'myip' %}")
.done(function( data ) { .done(function( data ) {
ip = data; ip = data;
$('#myip').text(ip);
$('#myip_timestamp').text(new Date().toISOString());
if(ip != last_ip) { if(ip != last_ip) {
$.ajax({ $.ajax({
url: "{% url 'nic_update' %}", url: "{% url 'nic_update' %}",
@ -33,10 +38,12 @@
}) })
.done(function( data ) { .done(function( data ) {
$('#response').text(data); $('#response').text(data);
$('#response_timestamp').text(new Date().toISOString());
last_ip = ip; last_ip = ip;
}) })
.fail(function (data) { .fail(function (data) {
$('#response').text('update failed'); $('#response').text('update failed');
$('#response_timestamp').text(new Date().toISOString());
}); });
} }
}) })