Pārlūkot izejas kodu

Merge branch 'rolling' into improve-iframe-sizing

CaCO3 3 gadi atpakaļ
vecāks
revīzija
d13f457344

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
sd-card/html/FileSaver.min.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
sd-card/html/FileSaver.min.js.map


+ 140 - 0
sd-card/html/backup.html

@@ -0,0 +1,140 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="icon" href="favicon.ico" type="image/x-icon">
+<title>Backup/Restore Configuration</title>
+<meta charset="utf-8">
+
+<style>
+h1 {font-size: 2em;}
+h2 {font-size: 1.5em;}
+h3 {font-size: 1.2em;} 
+p {font-size: 1em;}
+
+input[type=number] {
+	width: 138px;
+	padding: 10px 5px;
+	display: inline-block;
+	border: 1px solid #ccc;
+	font-size: 16px; 
+}
+
+.button {
+	padding: 10px 20px;
+    width: 211px;
+	font-size: 16px;
+}
+</style>
+
+</head>
+
+<body style="font-family: arial; padding: 0px 10px;">
+<h2>Backup Configuration</h2>
+<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">
+    </tr>
+        <td>
+            <button class="button" id="doBackup" type="button" onclick="doBackup()">Create Config backup</button>
+        </td>
+        <td>
+            <p id=progress></p>
+        </td>
+    </tr>
+</table>
+<hr>
+<h2>Restore Configuration</h2>
+<p>Use the <a href="/fileserver/config/" target="_self">File Server</a> to upload individual files.</p>
+</body>
+
+
+<script src="jszip.min.js"></script>
+<script src="FileSaver.min.js"></script>
+<script>
+
+function doBackup() {  
+    document.getElementById("progress").innerHTML = "Creating backup...";
+    
+    // Get hostname
+    try {
+        var xhttp = new XMLHttpRequest();
+        xhttp.open("GET", "/version?type=Hostname", false);
+        xhttp.send();
+        hostname = xhttp.responseText;
+    }
+    catch(err) {
+        alert("Failed to fetch hostname: " + err.message);
+        return;
+    }
+    
+    // get date/time
+    var dateTime = new Date().toJSON().slice(0,10) + "_" + new Date().toJSON().slice(11,19).replaceAll(":", "-");
+    
+    zipFilename = hostname + "_" + dateTime + ".zip";
+    console.log(zipFilename);
+
+    // Get files list
+    try {
+        var xhttp = new XMLHttpRequest();
+        xhttp.open("GET", "/fileserver/config/", false);
+        xhttp.send();
+        
+        var parser = new DOMParser();
+        var content = parser.parseFromString(xhttp.responseText, 'text/html');    }
+    catch(err) {
+        alert("Failed to fetch files list: " + err.message);
+        return;
+    }
+    
+    const list = content.querySelectorAll("a");
+    
+    var urls = [];
+    
+    for (a of list) {
+        url = a.getAttribute("href");
+        urls.push(url);
+    }
+    
+    // Pack as zip and download
+    try {
+        saveZip(zipFilename, urls);
+        }
+    catch(err) {
+        alert("Failed to zip files: " + err.message);
+        return;
+    }
+}
+
+
+const saveZip = (filename, urls) => {
+    if(!urls) return;
+
+    const zip = new JSZip();
+    const folder = zip.folder("");
+    
+    var i = 0;
+    urls.forEach((url) => {        
+        const blobPromise = fetch(url).then((r) => {
+            if (r.status === 200) return r.blob();
+            return Promise.reject(new Error(r.statusText));
+        });
+        const name = url.substring(url.lastIndexOf("/") + 1);
+        folder.file(name, blobPromise);
+    });
+
+    zip.generateAsync({ type: "blob" },
+        function updateCallback(metadata) {
+            var msg = "Progress: " + metadata.percent.toFixed(0) + "%";
+            if(metadata.currentFile) {
+                msg += ", " + metadata.currentFile;
+            }
+
+            console.log(msg);
+            document.getElementById("progress").innerHTML = msg;
+        }
+    ).then((blob) => saveAs(blob, filename));
+};
+
+</script>
+
+</html>

+ 1 - 0
sd-card/html/index.html

@@ -37,6 +37,7 @@
     <li class="dropdown">
 	<a href="javascript:void(0)" class="dropbtn">System</a>
 	<div class="dropdown-content">
+  	  <a href="#"onclick="document.getElementById('maincontent').src = '/backup.html';">Backup/Restore</a>
 	    <a href="#"onclick="document.getElementById('maincontent').src = '/ota_page.html';">OTA Update</a>
 	    <a href="#"onclick="document.getElementById('maincontent').src = '/fileserver/log/message/?readonly=true';">Log Viewer</a>      
 	    <a href="#"onclick="document.getElementById('maincontent').src = '/reboot_page.html';">Reboot</a>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 12 - 0
sd-card/html/jszip.min.js


+ 12 - 27
sd-card/html/ota_page.html

@@ -30,6 +30,7 @@ input[type=number] {
 
 <body style="font-family: arial; padding: 0px 10px;">
 <h3>It is strongly recommended to update firmware and content of /html directory on SD-card at the same time!</h3>
+<hr>
 <h2>1. Firmware Update</h2>
 <table class="fixed" border="0">
     <tr>
@@ -42,6 +43,9 @@ input[type=number] {
                     <td colspan="2">
                         <input id="newfile" type="file" onchange="setpath()" style="width:100%;">
                     </td>
+                    <td rowspan="2" style="padding-left:50px">
+                        <button class="button" id="doUpdate" type="button" onclick="doUpdate()">Flash the firmware<br>(Takes about 60s)</button>
+                    </td>
                 </tr>
                 <tr>
                     <td>
@@ -57,22 +61,8 @@ input[type=number] {
             </table>
         </td>
     </tr>
-	<tr>
-		<td>
-            <table border="0">
-                <tr>
-                    <td style="width: 230px">
-                        <button class="button" id="doUpdate" type="button" onclick="doUpdate()">Flash the firmware</button>
-                    </td>
-					<td>
-						(Takes about 60s)
-					</td>
-                </tr>
-            </table>		
-		</td>
-	</tr>
 </table>
-
+<hr>
 <h2>2. Update "/html" directory</h2>
 <table class="fixed" border="0">
     <tr>
@@ -85,6 +75,9 @@ input[type=number] {
                     <td colspan="2">
                         <input id="newfilehtml" type="file" onchange="setpathhtml()" style="width:100%;">
                     </td>
+                    <td rowspan="2" style="padding-left:50px">
+			<button class="button" id="doUpdatehtml" type="button" onclick="doUpdatehtml()">Update "/html" directory</button>
+                    </td>
                 </tr>
                 <tr>
                     <td>
@@ -100,20 +93,11 @@ input[type=number] {
             </table>
         </td>
     </tr>
-	<tr>
-		<td>
-			<button class="button" id="doUpdatehtml" type="button" onclick="doUpdatehtml()">Update "/html" directory</button>
-		</td>
-	</tr>
 </table>
+<hr>
 <h2>3. Reboot</h2>
-<table class="fixed" border="0">
-	<tr>
-		<td>
 			<button class="button" id="reboot" type="button" onclick="doReboot()">Reboot to activate updates</button>
-		</td>
-	</tr>
-</table>
+<hr>
 <h2>4. Upload neural network definition (tfl/tflite file)</h2>
 <table class="fixed" border="0">
     <tr>
@@ -141,7 +125,8 @@ input[type=number] {
             </table>
         </td>
     </tr>
-    The file must be activated in the config.ini file.
+    The file must be activated!
+    Use the <a href="index_configure.html" target="_parent">Config Page</a> or do it manually in the config.ini file.
 </table>
 
 

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels