mirror of
https://github.com/luc-github/ESP3D.git
synced 2025-10-31 11:56:48 -07:00
Add basic authentification and OTA update
only web update is supported
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
$INCLUDE[header.inc]$
|
||||
<div class="panel">
|
||||
<STYLE>
|
||||
input[type="file"]::-webkit-file-upload-button{display:inline-block;margin-bottom:0;font-weight:normal;text-align:center;vertical-align:middle;-ms-touch-action:manipulation; touch-action:manipulation;cursor:pointer;
|
||||
background-image:none;border:1px solid transparent;white-space:nowrap;padding:6px 12px;font-size:14px;line-height:1.42857143;border-radius:4px;
|
||||
* -webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none; color: #ffffff;background-color: #5bc0de;border-color: #46b8da;}
|
||||
input[type="file"]::-webkit-file-upload-button:focus{display:inline-block;margin-bottom:0;font-weight:normal;text-align:center;vertical-align:middle;-ms-touch-action:manipulation; touch-action:manipulation;cursor:pointer;
|
||||
background-image:none;border:1px solid transparent;white-space:nowrap;padding:6px 12px;font-size:14px;line-height:1.42857143;border-radius:4px;
|
||||
* -webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none; color: #ffffff;background-color: #31b0d5;border-color: #1b6d85;}
|
||||
input[type="file"]::-webkit-file-upload-button:hover{display:inline-block;margin-bottom:0;font-weight:normal;text-align:center;vertical-align:middle;-ms-touch-action:manipulation; touch-action:manipulation;cursor:pointer;
|
||||
background-image:none;border:1px solid transparent;white-space:nowrap;padding:6px 12px;font-size:14px;line-height:1.42857143;border-radius:4px;
|
||||
* -webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none; color: #ffffff;background-color: #31b0d5;border-color: #269abc;}
|
||||
</STYLE>
|
||||
<div id='system' class="panel">
|
||||
<div class="panel-heading">System</div>
|
||||
<div class="panel-body">
|
||||
<form method="POST">
|
||||
@@ -20,11 +31,74 @@ $SLEEP_MODE_OPTIONS_LIST$
|
||||
<div class="alert alert-danger" role="alert" style="$ERROR_MSG_VISIBILITY$" >
|
||||
$ERROR_MSG$
|
||||
</div>
|
||||
<hr><input style="$SUBMIT_BUTTON_VISIBILITY$" type="submit" class="btn btn-primary" name="SUBMIT" value="Apply">
|
||||
<hr><input id='btnsubmit' style="$SUBMIT_BUTTON_VISIBILITY$" type="submit" class="btn btn-primary" name="SUBMIT" value="Apply">
|
||||
</form>
|
||||
<div class="alert alert-success" role="alert" style="$SUCCESS_MSG_VISIBILITY$" >
|
||||
$SUCCESS_MSG$
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel">
|
||||
<div class="panel-heading">Firmware Update</div>
|
||||
<div class="panel-body">
|
||||
<table><tr>
|
||||
<td><input type="file" id="file-select" name="myfiles[]" multiple /></td>
|
||||
<td><input class="btn btn-primary" type="button" id="upload-button" onclick="Sendfile();" value="Update"/></td>
|
||||
<td><progress style="visibility:hidden;" name='prg' id='prg'></progress></td>
|
||||
<td><div id='msg' style='visibility:hidden;'>Restarting, please wait....</div></td></tr></table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
function Sendfile(){
|
||||
if (!confirm("Confirm Firmware Update ?"))return;
|
||||
var files = document.getElementById('file-select').files;
|
||||
if (files.length==0)return;
|
||||
document.getElementById('upload-button').value = "Uploading...";
|
||||
document.getElementById('prg').style.visibility = "visible";
|
||||
var formData = new FormData();
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var file = files[i];
|
||||
formData.append('myfiles[]', file, "/"+file.name);}
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.open('POST', '/UPDATE', true);
|
||||
xmlhttp.onload = function () {
|
||||
if (xmlhttp.status === 200) {
|
||||
document.getElementById('upload-button').value = 'Upload';
|
||||
document.getElementById('upload-button').style.visibility = 'hidden';
|
||||
document.getElementById('upload-button').style.width = '0px';
|
||||
document.getElementById('system').style.visibility = 'hidden';
|
||||
document.getElementById('system').style.height = '0px';
|
||||
document.getElementById('msg').style.visibility = "visible";
|
||||
document.getElementById('file-select').value="";
|
||||
document.getElementById('file-select').style.visibility = 'hidden';
|
||||
document.getElementById('file-select').style.width = '0px';
|
||||
document.getElementById('btnsubmit').style.visibility = 'hidden';
|
||||
|
||||
var jsonresponse = JSON.parse(xmlhttp.responseText);
|
||||
if (jsonresponse.status=='1' || jsonresponse.status=='4' || jsonresponse.status=='1')alert("Update failed");
|
||||
if (jsonresponse.status=='2')alert('Update canceled!');
|
||||
else if (jsonresponse.status=='3')
|
||||
{
|
||||
var i = 0;
|
||||
var interval;
|
||||
var x = document.getElementById("prg");
|
||||
x.max=40;
|
||||
interval = setInterval(function(){
|
||||
i=i+1;
|
||||
var x = document.getElementById("prg");
|
||||
x.value=i;
|
||||
if (i>40)
|
||||
{
|
||||
clearInterval(interval);
|
||||
location.reload();
|
||||
}
|
||||
},1000);
|
||||
}
|
||||
else alert('Update failed!');
|
||||
} else alert('An error occurred!');
|
||||
}
|
||||
xmlhttp.send(formData);
|
||||
}
|
||||
</script>
|
||||
$INCLUDE[footer.inc]$
|
||||
|
||||
Reference in New Issue
Block a user