This commit is contained in:
George Ruinelli
2022-08-30 17:54:21 +02:00
parent 6417f780e6
commit d0968e87d7

View File

@@ -30,7 +30,7 @@ input[type=number] {
<body style="font-family: arial; padding: 0px 10px;"> <body style="font-family: arial; padding: 0px 10px;">
<h2>Backup Configuration</h2> <h2>Backup Configuration</h2>
<p>With the following action the config folder on the SD-card gets zipped and provided as a download.</p> <p>With the following action the <a href="/fileserver/config/" target="_self">config</a> folder on the SD-card gets zipped and provided as a download.</p>
<table border="0"> <table border="0">
</tr> </tr>
@@ -44,8 +44,7 @@ input[type=number] {
</table> </table>
<hr> <hr>
<h2>Restore Configuration</h2> <h2>Restore Configuration</h2>
<p>Not implemented yet.<br> <p>Use the <a href="/fileserver/config/" target="_self">File Server</a> to upload individual files.</p>
But you can use the <a href="/fileserver/config" target="_self">File Server</a> to upload individual files.</p>
</body> </body>
@@ -54,15 +53,19 @@ But you can use the <a href="/fileserver/config" target="_self">File Server</a>
<script> <script>
function doBackup() { function doBackup() {
document.getElementById("progress").innerHTML = "Creating backup..."; document.getElementById("progress").innerHTML = "Creating backup...";
// Get hostname // Get hostname
try {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.open("GET", "/version?type=Hostname", false); xhttp.open("GET", "/version?type=Hostname", false);
xhttp.send(); xhttp.send();
hostname = xhttp.responseText; hostname = xhttp.responseText;
}
catch(err) {
alert("Failed to fetch hostname: " + err.message);
return;
}
// get date/time // get date/time
var dateTime = new Date().toJSON().slice(0,10) + "_" + new Date().toJSON().slice(11,19).replaceAll(":", "-"); var dateTime = new Date().toJSON().slice(0,10) + "_" + new Date().toJSON().slice(11,19).replaceAll(":", "-");
@@ -71,12 +74,17 @@ function doBackup() {
console.log(zipFilename); console.log(zipFilename);
// Get files list // Get files list
try {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.open("GET", "/fileserver/config/", false); xhttp.open("GET", "/fileserver/config/", false);
xhttp.send(); xhttp.send();
var parser = new DOMParser(); var parser = new DOMParser();
var content = parser.parseFromString(xhttp.responseText, 'text/html'); var content = parser.parseFromString(xhttp.responseText, 'text/html'); }
catch(err) {
alert("Failed to fetch files list: " + err.message);
return;
}
const list = content.querySelectorAll("a"); const list = content.querySelectorAll("a");
@@ -88,7 +96,13 @@ function doBackup() {
} }
// Pack as zip and download // Pack as zip and download
try {
saveZip(zipFilename, urls); saveZip(zipFilename, urls);
}
catch(err) {
alert("Failed to zip files: " + err.message);
return;
}
} }
@@ -123,5 +137,4 @@ const saveZip = (filename, urls) => {
</script> </script>
</html> </html>