浏览代码

2020-09-18 / ct_chen

Actions:
1. optimize UI of upgrade
2. http not force to https

Files:
1. EVSE/Modularization/WebService.c
   EVSE/rootfs/var/www/upgrade_iso.php
   EVSE/rootfs/var/www/img/5minutes.gif

2. EVSE/rootfs/etc/lighttpd/conf.d/ssl.conf
ct_chen 4 年之前
父节点
当前提交
503e897bb9

+ 1 - 1
EVSE/Modularization/WebService.c

@@ -968,7 +968,7 @@ int main(int argc, char *argv[]) {
 		//if((char)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == '0'){
 		ShmSysConfigAndInfo->SysInfo.FirmwareUpdate=1;
 		Result = json_object_new_string("success");
-		Message = json_object_new_string("file is uploaded");
+		Message = json_object_new_string("File is uploaded, please wait a moment to upgrade");
 		//}
 		/*else{
 			sprintf(cmd,"rm /mnt/%s",argv[2]);

+ 1 - 1
EVSE/rootfs/etc/lighttpd/conf.d/ssl.conf

@@ -6,7 +6,7 @@ $HTTP["scheme"] == "http" {
     # capture vhost name with regex conditiona -> %0 in redirect pattern
     # must be the most inner block to the redirect rule
     $HTTP["host"] =~ ".*" {
-        url.redirect = (".*" => "https://%0$0")
+#        url.redirect = (".*" => "https://%0$0")
     }
 }
 

二进制
EVSE/rootfs/var/www/img/5minutes.gif


+ 65 - 14
EVSE/rootfs/var/www/upgrade_iso.php

@@ -30,12 +30,13 @@ img {
 		Main Content start
 		//-->
 		<a id="loadinghref"><div id="loading" style="display:none;"><img src="img/giphy.gif"/></div></a>
+		<div id="loading2" style="display:none;"><img src="img/5minutes.gif"/></div>
 		<section class="envor-section">
 			<div class="container">
 				<div class="row">
 					<div class="col-lg-12">
 						<h2>Image <?php echo $lang->showWord("upgrade");?></h2>
-						<div class="file-loading"> 
+						<div class="file-loading">
 							<input name="file_iso" id="file_iso" type="file" class="file" data-show-preview="false" data-show-upload="false" <?php //data-allowed-file-extensions='["iso"]' ?>>
 						</div>
 
@@ -45,7 +46,7 @@ img {
 									<div align="center"><button id="upload_iso"><?php echo $lang->showWord("set")?></button></div>
 								</article>
 					</div>
-		
+
 					<div class="col-lg-12">
 						<h2><?php echo $lang->showWord("upgrade_status");?></h2>
 <!--                <textarea id="description" rows="2" class="form-control" placeholder=""></textarea>-->
@@ -59,7 +60,7 @@ img {
 		</section>
 	</div>
 
-<?php 
+<?php
 	include 'foot.php';
 ?>
 
@@ -71,7 +72,7 @@ img {
 			window.location="#loadinghref";
 			document.getElementById("loading").style.display="block";
 			var fileInput = document.getElementById('file_iso');
-			
+
 			// 發送 Ajax 查詢請求並處理
 			var request = new XMLHttpRequest();
 			request.open("POST", "upgrade_iso_action.php");
@@ -96,7 +97,34 @@ img {
 					if (request.status == 200) {
 						document.getElementById("createResult").innerHTML = "";
 						document.getElementById("createResult").innerHTML = request.responseText;
+						document.getElementById("loading2").style.display="block";
+						var ts = 4*60*1000;
+						var idx=0;
+						var x = setInterval(function() { 
+							idx++;
+							var t=ts-1000*idx;
+							if (t < 0) { 
+								clearInterval(x); 
+								document.getElementById("createResult").innerHTML = "<font color='#ff0000'>Upgrade done!</font>";
+								document.getElementById("loading2").style.display="none";
+								//location.href="upgrade_iso.php";
+							}
+						}, 1000); 
+						var cnt=0;
 						//location.href="upgrade_iso.php";
+						setInterval(function(){
+							var result=serverReachable();
+							if(!result) cnt=1;
+							if(result && cnt==1) cnt=2;
+							if(cnt==2) {
+								document.getElementById("createResult").innerHTML = "<font color='#ff0000'>Upgrade done!</font>";
+								document.getElementById("loading2").style.display="none";
+//								cnt=3;
+								//location.href="upgrade_iso.php";
+								//return false;
+							}
+//							if(cnt==3)return false;
+							},3000);
 					} else {
 						alert(JSON.parse(request.responseText).message);
 					}
@@ -108,29 +136,29 @@ img {
 			}
 		}
 	}
-	
+
 	function formCheck(fw_tag)
 	{
 		var file_type;
-		
+
 		if(fw_tag=="iso")
 		{
 			if(document.getElementById("file_iso").value.substring(document.getElementById("file_iso").value.length-3) != "hex")
 			{
 //				alert("Firmware file type is wrong, please check file type.(*.hex)");
 //				document.getElementById("file_iso").focus();
-				
+
 //				return false;
 			}
-		 
+
 			if(document.getElementById("file_iso").value.length <= 0)
 			{
 				alert("Firmware is not select, please check!");
 				document.getElementById("file_iso").focus();
-				
+
 				return false;
-			}	
-			
+			}
+
 //			if(confirm("Are you sure to update AC MCU firmware file now?...") == 1 )
 				return true;
 			// else
@@ -143,12 +171,35 @@ img {
 	function isNumberKey(evt)
 	{
 		var charCode = (evt.which) ? evt.which : event.keyCode
-		
+
 		if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
 			return false;
-		
+
 		return true;
 	}
-	
+
+	function serverReachable() {
+		// IE vs. standard XHR creation
+		var x = new ( window.ActiveXObject || XMLHttpRequest )( "Microsoft.XMLHTTP" ),
+		s;
+		x.open(
+			// requesting the headers is faster, and just enough
+			"HEAD",
+			// append a random string to the current hostname,
+			// to make sure we're not hitting the cache
+			"//" + window.location.hostname + "/?rand=" + Math.random(),
+			// make a synchronous request
+			false
+		);
+		try {
+			x.send();
+			s = x.status;
+			// Make sure the server is reachable
+			return ( s >= 200 && s < 300 || s === 304 );
+			// catch network & other problems
+		} catch (e) {
+			return false;
+		}
+	}
 </script>