Implement firmware auto-update
This commit is contained in:
parent
6e6c63bed8
commit
36994cb03b
4 changed files with 31 additions and 3 deletions
|
@ -28,7 +28,7 @@
|
|||
{% endif %}
|
||||
<div class="form-group">
|
||||
<label for="name">Device Name</label>
|
||||
<input type="text" class="form-control" name="name" id="name" placeholder="Enter Device Name (Optional)" value="{{ device.name }}"></input>
|
||||
<input type="text" class="form-control" name="name" id="name" placeholder="Enter Device Name (Optional)" {% if device.name %} value="{{ device.name }}" {% endif %}></input>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="subnet">Assigned Network</label>
|
||||
|
@ -43,6 +43,12 @@
|
|||
<input class="form-check-input" type="checkbox" value="True" {% if device.reboot %} checked {% endif %} id="reboot" name="reboot">
|
||||
<label class="form-check-label" for="reboot">Reboot device immediately </label>
|
||||
</div>
|
||||
{% if user.is_staff %}
|
||||
<div class="form-group form-check">
|
||||
<input class="form-check-input" type="checkbox" value="True" {% if device.update %} checked {% endif %} id="update" name="update">
|
||||
<label class="form-check-label" for="update">Install Firmware Update</label>
|
||||
</div>
|
||||
{% endif %}
|
||||
<button type="submit" class="btn btn-success">Apply Changes</button>
|
||||
<a class="btn btn-danger" href="/" role="button">Cancel</a>
|
||||
</form>
|
||||
|
|
|
@ -12,5 +12,6 @@ urlpatterns = [
|
|||
path('devices/<int:device_id>/delete/', views.deletedevice, name="deletedevice"),
|
||||
path('devices/<int:device_id>/reboot/', views.rebootdevice, name="rebootdevice"),
|
||||
path('heartbeat', views.heartbeat, name='heartbeat'),
|
||||
path('makedevice/', views.makedevice, name="makedevice")
|
||||
path('makedevice/', views.makedevice, name="makedevice"),
|
||||
path('update', views.update, name='update')
|
||||
]
|
||||
|
|
|
@ -40,7 +40,22 @@ def heartbeat(request):
|
|||
device.curip = ip
|
||||
|
||||
device.save()
|
||||
return HttpResponse("reboot" if device.reboot else "")
|
||||
|
||||
code = ""
|
||||
|
||||
if device.update:
|
||||
code += """
|
||||
. /etc/vpnsecret
|
||||
if /usr/bin/wget -O/tmp/update.bin https://admin360.kumi.host/update --post-data "secret=$SECRET" --no-check-certificate 2>/var/log/wget;
|
||||
then
|
||||
/sbin/sysupgrade -F -n /tmp/update.bin
|
||||
fi
|
||||
"""
|
||||
|
||||
if device.reboot:
|
||||
code += "\nreboot"
|
||||
|
||||
return HttpResponse(code)
|
||||
|
||||
@csrf_exempt
|
||||
def hosts(request):
|
||||
|
@ -185,6 +200,7 @@ def ping(request, device_id):
|
|||
ajax += ',\n "time": "%s"' % device[0].lasttime
|
||||
ajax += ',\n "lastbeat": "%s"' % device[0].lastbeat
|
||||
ajax += ',\n "reboot": %i' % (1 if device[0].reboot else 0)
|
||||
ajax += ',\n "update": %i' % (1 if device[0].update else 0)
|
||||
|
||||
ajax += ',\n "network": {'
|
||||
ajax += '\n "intip": "%s"' % device[0].network.intip
|
||||
|
@ -241,6 +257,7 @@ def editdevice(request, device_id):
|
|||
device[0].name = request.POST.get("name", "")
|
||||
device[0].network = subnet[0]
|
||||
device[0].reboot = True if request.POST.get("reboot", "0") == "True" else False
|
||||
device[0].update = True if request.POST.get("update", "0") == "True" else False
|
||||
device[0].save()
|
||||
|
||||
return redirect("/")
|
||||
|
|
|
@ -36,6 +36,10 @@ function styleStatus(msg, device) {
|
|||
device_id.css("font-style", msg.reboot == 1 ? "italic" : "normal")
|
||||
};
|
||||
|
||||
if (msg.hasOwnProperty("update")) {
|
||||
device_id.css("font-weight", msg.update == 1 ? "bold" : "normal")
|
||||
};
|
||||
|
||||
if (msg.hasOwnProperty("name")) {
|
||||
device_name.text(msg.name);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue