Эх сурвалжийг харах

2019-12-04 / ct_chen

Actions:
1. webservice fix bug and optimization

Files:
1. EVSE/Modularization/WebService.c
   EVSE/rootfs/var/www/*
ct_chen 5 жил өмнө
parent
commit
5ce84d08c5

+ 27 - 30
EVSE/Modularization/WebService.c

@@ -355,10 +355,10 @@ int main(int argc, char *argv[]) {
 		if (strcmp(argv[1], "2") == 0) {
 			struct json_object *jobj = json_tokener_parse(argv[2]);
 			json_object *val_obj = NULL;
-			const char *MaxChargingEnergy=NULL;
-			const char *MaxChargingPower = NULL;
-			const char *MaxChargingCurrent = NULL;
-			const char *MaxChargingDuration = NULL;
+			const int *MaxChargingEnergy= 0;
+			const int *MaxChargingPower = 0;
+			const int *MaxChargingCurrent = 0;
+			const int *MaxChargingDuration = 0;
 			const char *PhaseLossPolicy = NULL;
 			const char *LocalWhiteCard0 = NULL;
 			const char *LocalWhiteCard1 = NULL;
@@ -372,16 +372,16 @@ int main(int argc, char *argv[]) {
 			const char *LocalWhiteCard9 = NULL;
 
 			if( json_object_object_get_ex(jobj, "MaxChargingEnergy", &val_obj) ) {
-				MaxChargingEnergy = json_object_get_string(val_obj);
+				MaxChargingEnergy = json_object_get_int(val_obj);
 			}
 			if( json_object_object_get_ex(jobj, "MaxChargingPower", &val_obj) ) {
-				MaxChargingPower = json_object_get_string(val_obj);
+				MaxChargingPower = json_object_get_int(val_obj);
 			}
 			if( json_object_object_get_ex(jobj, "MaxChargingCurrent", &val_obj) ) {
-				MaxChargingCurrent = json_object_get_string(val_obj);
+				MaxChargingCurrent = json_object_get_int(val_obj);
 			}
 			if( json_object_object_get_ex(jobj, "MaxChargingDuration", &val_obj) ) {
-				MaxChargingDuration = json_object_get_string(val_obj);
+				MaxChargingDuration = json_object_get_int(val_obj);
 			}
 			if( json_object_object_get_ex(jobj, "PhaseLossPolicy", &val_obj) ) {
 				PhaseLossPolicy = json_object_get_string(val_obj);
@@ -416,10 +416,10 @@ int main(int argc, char *argv[]) {
 			if( json_object_object_get_ex(jobj, "LocalWhiteCard9", &val_obj) ) {
 				LocalWhiteCard9 = json_object_get_string(val_obj);
 			}
-			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy,MaxChargingEnergy);
-			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.MaxChargingPower,MaxChargingPower);
-			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent,MaxChargingCurrent);
-			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.MaxChargingDuration,MaxChargingDuration);
+			ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = MaxChargingEnergy;
+			ShmSysConfigAndInfo->SysConfig.MaxChargingPower = MaxChargingPower;
+			ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = MaxChargingCurrent;
+			ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = MaxChargingDuration;
 			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy,PhaseLossPolicy);
 			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[0],LocalWhiteCard0);
 			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[1],LocalWhiteCard1);
@@ -432,10 +432,10 @@ int main(int argc, char *argv[]) {
 			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[8],LocalWhiteCard8);
 			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[9],LocalWhiteCard9);
 			//Set default configuration
-			strcpy((char *)&SysConfig.MaxChargingEnergy, MaxChargingEnergy);
-			strcpy((char *)&SysConfig.MaxChargingPower, MaxChargingPower);
-			strcpy((char *)&SysConfig.MaxChargingCurrent, MaxChargingCurrent);
-			strcpy((char *)&SysConfig.MaxChargingDuration,MaxChargingDuration);
+			SysConfig.MaxChargingEnergy = MaxChargingEnergy;
+			SysConfig.MaxChargingPower = MaxChargingPower;
+			SysConfig.MaxChargingCurrent = MaxChargingCurrent;
+			SysConfig.MaxChargingDuration = MaxChargingDuration;
 			strcpy((char *)&SysConfig.PhaseLossPolicy,PhaseLossPolicy);
 			strcpy((char *)&SysConfig.LocalWhiteCard[0],LocalWhiteCard0);
 			strcpy((char *)&SysConfig.LocalWhiteCard[1],LocalWhiteCard1);
@@ -490,7 +490,7 @@ int main(int argc, char *argv[]) {
 			if( json_object_object_get_ex(jobj, "Eth1DhcpClient", &val_obj) ) {
 				Eth1DhcpClient = json_object_get_string(val_obj);
 			}
-			if( json_object_object_get_ex(jobj, "Eth10IpAddress", &val_obj) ) {
+			if( json_object_object_get_ex(jobj, "Eth1IpAddress", &val_obj) ) {
 				Eth1IpAddress = json_object_get_string(val_obj);
 			}
 			if( json_object_object_get_ex(jobj, "Eth1SubmaskAddress", &val_obj) ) {
@@ -591,16 +591,19 @@ int main(int argc, char *argv[]) {
 			const char *ChargeBoxId=NULL;
 
 			if( json_object_object_get_ex(jobj, "BackendConnTimeout", &val_obj) ) {
-				BackendConnTimeout =(int *)json_object_get_int(val_obj);
+				//BackendConnTimeout = json_object_get_string(val_obj);
+				BackendConnTimeout = json_object_get_int(val_obj);
 			}
 			if( json_object_object_get_ex(jobj, "OfflinePolicy", &val_obj) ) {
 				OfflinePolicy = json_object_get_string(val_obj);
 			}
 			if( json_object_object_get_ex(jobj, "OfflineMaxChargeEnergy", &val_obj) ) {
-				OfflineMaxChargeEnergy = (int *)json_object_get_int(val_obj);
+				//OfflineMaxChargeEnergy = json_object_get_string(val_obj);
+				OfflineMaxChargeEnergy = json_object_get_int(val_obj);
 			}
 			if( json_object_object_get_ex(jobj, "OfflineMaxChargeDuration", &val_obj) ) {
-				OfflineMaxChargeDuration = (int *)json_object_get_int(val_obj);
+				//OfflineMaxChargeDuration = json_object_get_string(val_obj);
+				OfflineMaxChargeDuration = json_object_get_int(val_obj);
 			}
 			if( json_object_object_get_ex(jobj, "OcppServerURL", &val_obj) ) {
 				OcppServerURL = json_object_get_string(val_obj);
@@ -609,10 +612,10 @@ int main(int argc, char *argv[]) {
 				ChargeBoxId = json_object_get_string(val_obj);
 			}
 
-			SysConfig.BackendConnTimeout=(int)BackendConnTimeout;
+			ShmSysConfigAndInfo->SysConfig.BackendConnTimeout = BackendConnTimeout;
 			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.OfflinePolicy,OfflinePolicy);
-			SysConfig.OfflineMaxChargeEnergy=(int)OfflineMaxChargeEnergy;
-			SysConfig.OfflineMaxChargeDuration=(int)OfflineMaxChargeDuration;
+			ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = OfflineMaxChargeEnergy;
+			ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration = OfflineMaxChargeDuration;
 			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,OcppServerURL);
 			strcpy((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId,ChargeBoxId);
 			//Set default configuration
@@ -679,9 +682,6 @@ int main(int argc, char *argv[]) {
 		ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes=0;
 		ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes=0;
 		//Set default configuration
-		//strcpy(SysConfig->ModelName)
-//		strcpy(SysConfig->SystemId, ShmSysConfigAndInfo->SysConfig.SystemId);
-//		strcpy(SysConfig->SystemDateTime, ShmSysConfigAndInfo->SysConfig.SystemDateTime);
 		strcpy(SysConfig.SystemId, "0987654321");
 		strcpy(SysConfig.SystemDateTime, "2019-08-12 00:00:00");
 		//charging
@@ -744,7 +744,6 @@ int main(int argc, char *argv[]) {
 		strcpy((char *)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd,"TelcomChapPapPwd");
 		strcpy((char *)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei,"TelcomModemImei");
 		strcpy((char *)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi,"TelcomSimImsi");
-		//sprintf(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid,"TelcomSimIccid");
 		strcpy((char *)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus,"1");
 		strcpy((char *)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode,"1");
 		strcpy((char *)&ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress,"TelcomIpAddress");
@@ -819,9 +818,6 @@ int main(int argc, char *argv[]) {
 		connectorType2=ConnectorType((char *)Connector2);
 		connectorType3=ConnectorType((char *)Connector3);
 //		modelType=ModelType((char *)IsAcDc,(char *)Network);
-//		printf("connectorType1:%d\n",connectorType1);
-//		printf("connectorType2:%d\n",connectorType2);
-//		printf("connectorType3:%d\n",connectorType3);
 //		printf("modelType:%d\n",modelType);
 
 		struct json_object *jobj1;
@@ -1285,6 +1281,7 @@ int main(int argc, char *argv[]) {
 		json_object_object_add(jobj1,"SerialNumber",SerialNumber);
 		json_object_object_add(jobj1,"SystemId",SystemId);
 //		json_object_object_add(jobj1,"SystemDateTime",SystemDateTime);
+		json_object_object_add(jobj1,"AcPhaseCount",AcPhaseCount);
 		json_object_object_add(jobj1,"FactoryConfiguration",FactoryConfiguration);
 		json_object_object_add(jobj1,"AuthorisationMode",AuthorisationMode);
 		json_object_object_add(jobj1,"DefaultLanguage",DefaultLanguage);

+ 2 - 2
EVSE/rootfs/var/www/foot.php

@@ -1,5 +1,5 @@
 <!--	<footer class="fixed-bottom envor-footer">-->
-	<footer class="fixed-bottom envor-footer">
+<?php /*	<footer class="fixed-bottom envor-footer">
 
       <div class="container">
         <div class="row">
@@ -39,7 +39,7 @@
     Envor footer end
 
     //-->
-    </footer>
+    </footer>*/?>
 
     <!-- Bootstrap core JavaScript
     ================================================== -->

+ 14 - 11
EVSE/rootfs/var/www/head.php

@@ -5,6 +5,9 @@
 <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
 <?php
 	ini_set('error_reporting', E_ERROR | E_WARNING | E_PARSE);
+			if(file_exists("/Storage/settings")){
+				exec("cp /Storage/settings settings");
+			}
 	$json = json_decode(file_get_contents("settings"), true);
 	
 	include 'valid.php';
@@ -96,14 +99,14 @@
 
 ?>
 
-  <head>
-    <meta charset="utf-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <meta name="description" content="EV System Configuration">
-    <link rel="shortcut icon" href="favicon.ico">
+	<head>
+		<meta charset="utf-8">
+		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+		<meta name="viewport" content="width=device-width, initial-scale=1.0">
+		<meta name="description" content="EV System Configuration">
+		<link rel="shortcut icon" href="favicon.ico">
 
-    <title>EV System Configuration</title>
+		<title>EV System Configuration</title>
 
 
     <!--
@@ -209,9 +212,9 @@
 				<li<?php echo ($tag_header=='other'?' class="active"':''); ?>>
 					<a href="#" accesskey="3" title="Other"><?php echo $lang->showWord("other"); ?></a>
 					<ul>	
-						<li>
+<?php /*						<li>
 						  <a href="set_contact.php"><?php echo $lang->showWord("contact_info"); ?></a>
-						</li>
+						</li>*/?>
 						<li>
 						  <a href="log_download.php"><?php echo $lang->showWord("log_download"); ?></a>
 						</li>
@@ -323,9 +326,9 @@
 					<li<?php echo ($tag_header=='other'?' class="active"':''); ?>>
                       <a href="#" accesskey="3" title="Other"><?php echo $lang->showWord("other"); ?></a>
                       <ul>
-						<li>
+<?php /*						<li>
 						  <a href="set_contact.php"><?php echo $lang->showWord("contact_info"); ?></a>
-						</li>
+						</li>*/?>
 						<li>
 						  <a href="log_download.php"><?php echo $lang->showWord("log_download"); ?></a>
 						</li>

+ 1 - 1
EVSE/rootfs/var/www/set_backend.php

@@ -117,7 +117,7 @@
 						"&OfflinePolicy=" + document.getElementById("OfflinePolicy").value +
 						"&OfflineMaxChargeEnergy=" + document.getElementById("OfflineMaxChargeEnergy").value+
 						"&OfflineMaxChargeDuration=" + document.getElementById("OfflineMaxChargeDuration").value+
-						"&OcppConnStatus=" + document.getElementById("OcppConnStatus").value+
+//						"&OcppConnStatus=" + document.getElementById("OcppConnStatus").value+
 						"&OcppServerURL=" + document.getElementById("OcppServerURL").value+
 						"&ChargeBoxId=" + document.getElementById("ChargeBoxId").value;
 			

+ 14 - 5
EVSE/rootfs/var/www/set_backend_action.php

@@ -18,18 +18,27 @@
 		$json['OfflinePolicy']				= $_POST['OfflinePolicy'];
 		$json['OfflineMaxChargeEnergy']		= (int)$_POST['OfflineMaxChargeEnergy'];
 		$json['OfflineMaxChargeDuration']	= (int)$_POST['OfflineMaxChargeDuration'];
-		$json['OcppConnStatus']				= $_POST['OcppConnStatus'];
+//		$json['OcppConnStatus']				= $_POST['OcppConnStatus'];
 		$json['OcppServerURL']				= $_POST['OcppServerURL'];
 		$json['ChargeBoxId']				= $_POST['ChargeBoxId'];
-		var_dump($json);echo "\n\n";
-		echo json_encode($json);
-		
+		$pattern="/^(ws|wss):\/\/((([0-9]{1,3}\.){3}[0-9]{1,3})|(([a-zA-Z0-9]+(([\-]?[a-zA-Z0-9]+)*\.)+)*[a-zA-Z]{2,}))+/";
+		if(!preg_match($pattern, $_POST['OcppServerURL'])){
+			$jsone['result'] = "Fail";
+			$jsone['message'] = "OcppServerURL format error, fill it with 'ws://' or 'wss://'";
+			echo json_encode($jsone);
+			return false;
+		}
+//		var_dump($json);echo "\n\n";
+		//echo json_encode($json);
+		$jsone['result'] = "Success";
+		$jsone['message'] = $json;
+		echo json_encode($jsone);
 		ob_start();
 		
 		shell_exec('sync;sync;sync');
 //		chdir("/home/phihong/Module_WebService");
 		chdir("/root");
-		$str_json=json_encode($json);var_dump($str_json);
+		$str_json=json_encode($json);//var_dump($str_json);
 		exec("'./WebService' '4' '".$str_json."'",$output,$return_var);
 //		copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
 		ob_end_clean();	

+ 2 - 30
EVSE/rootfs/var/www/set_charging.php

@@ -37,7 +37,7 @@
 									<section>
 										<div class="form-group" style="display:<?php echo $am111;?>">
 											<label>MaxChargingEnergy</label>
-											<input type="text" name="MaxChargingEnergy" id="MaxChargingEnergy" class="form-control" value="<?php echo $ob['MaxChargingEnergy'];?>">
+											<input type="text" name="MaxChargingEnergy" id="MaxChargingEnergy" class="form-control" value="<?php echo $obj['MaxChargingEnergy'];?>">
 										</div>
 										<div class="form-group" style="display:<?php echo $am001;?>">
 											<label>MaxChargingPower</label>
@@ -329,17 +329,7 @@
 						"&LocalWhiteCard8=" + document.getElementById("LocalWhiteCard8").value+
 						"&LocalWhiteCard9=" + document.getElementById("LocalWhiteCard9").value+
 						"&CcsAuthentication=" + document.getElementById("CcsAuthentication").value+
-						"&AcCcsChargingModel=" + document.getElementById("AcCcsChargingModel").value+
-						"&UserId=" + document.getElementById("UserId").value+
-						"&PresentChargingVoltage=" + document.getElementById("PresentChargingVoltage").value+
-						"&PresentChargingCurrent=" + document.getElementById("PresentChargingCurrent").value+
-						"&PresentChargingPower=" + document.getElementById("PresentChargingPower").value+
-						"&PresentChargedEnergy=" + document.getElementById("PresentChargedEnergy").value+
-						"&PresentChargedDuration=" + document.getElementById("PresentChargedDuration").value+
-						"&RemainChargingDuration=" + document.getElementById("RemainChargingDuration").value+
-						"&EvBatteryMaxVoltage=" + document.getElementById("EvBatteryMaxVoltage").value+
-						"&EvBatterytargetVoltage=" + document.getElementById("EvBatterytargetVoltage").value+
-						"&EvBatterySoc=" + document.getElementById("EvBatterySoc").value;
+						"&AcCcsChargingModel=" + document.getElementById("AcCcsChargingModel").value;
 			
 			// POST 請求必須設置表頭在 open() 下面,send() 上面
 			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
@@ -396,24 +386,6 @@
 			return false;
 		}
 		
-		// if(serverAddr.length <=0)
-		// {
-			// alert("Please check remote server address!");
-			  // serverAddr.focus();
-			  // return false;
-		// }
-		
-		// if((serverPort.value >65535) || (serverPort.value<0))
-		// {
-			// alert("Please check remote server port, it's must <= 65535!");
-			  // serverPort.focus();
-			  // return false;
-		// }
-		
-		// if( confirm("Are you sure to update ID to " + ChargerID + "?") == 1 )
-			// return true;
-		// else
-			// return false;
 		return true;
 	}
 

+ 34 - 17
EVSE/rootfs/var/www/set_charging_action.php

@@ -14,10 +14,6 @@
 	function create() {
 //		$json = json_decode(file_get_contents("charging.txt"), true);
 //		$json = string[];
-		// $json['MaxChargingEnergy']			= base_convert($_POST['MaxChargingEnergy'],10,16);
-		// $json['MaxChargingPower'] 			= base_convert($_POST['MaxChargingPower'],10,16);
-		// $json['MaxChargingCurrent']			= base_convert($_POST['MaxChargingCurrent'],10,16);
-		// $json['MaxChargingDuration'] 		= base_convert($_POST['MaxChargingDuration'],10,16);
 		$json['MaxChargingEnergy']			= (int)$_POST['MaxChargingEnergy'];
 		$json['MaxChargingPower'] 			= (int)$_POST['MaxChargingPower'];
 		$json['MaxChargingCurrent']			= (int)$_POST['MaxChargingCurrent'];
@@ -35,18 +31,16 @@
 		$json['LocalWhiteCard9']			= $_POST['LocalWhiteCard9'];
 		$json['CcsAuthentication']			= $_POST['CcsAuthentication'];
 		$json['AcCcsChargingModel']			= $_POST['AcCcsChargingModel'];
-		$json['UserId']						= $_POST['UserId'];
-		$json['PresentChargingVoltage']		= $_POST['PresentChargingVoltage'];
-		$json['PresentChargingCurrent']		= $_POST['PresentChargingCurrent'];
-		$json['PresentChargingPower']		= $_POST['PresentChargingPower'];
-		$json['PresentChargedEnergy']		= $_POST['PresentChargedEnergy'];
-		$json['PresentChargedDuration']		= $_POST['PresentChargedDuration'];
-		$json['RemainChargingDuration']		= $_POST['RemainChargingDuration'];
-		$json['EvBatteryMaxVoltage']		= $_POST['EvBatteryMaxVoltage'];
-		$json['EvBatterytargetVoltage']		= $_POST['EvBatterytargetVoltage'];
-		$json['EvBatterySoc']				= $_POST['EvBatterySoc'];
-		var_dump($json);echo "\n\n";
-		echo json_encode($json);
+		checkMaxValue("MaxChargingEnergy");
+		checkMaxValue("MaxChargingPower");
+		checkMaxValue("MaxChargingCurrent");
+		checkMaxValue("MaxChargingDuration");
+		
+//		var_dump($json);echo "\n\n";
+//		echo json_encode($json);
+		$jsone['result'] = "Success";
+		$jsone['message'] = $json;
+		echo json_encode($jsone);
 		//file_put_contents("system.dat", json_encode($json));
 		
 		// $json = json_decode(file_get_contents("rateOnline"), true);
@@ -71,7 +65,7 @@
 		shell_exec('sync;sync;sync');
 		//chdir("/home/phihong/Module_WebService");
 		chdir("/root");
-		$str_json=json_encode($json);var_dump($str_json);
+		$str_json=json_encode($json);//var_dump($str_json);
 		exec("'./WebService' '2' '".$str_json."'",$output,$return_var);
 //		copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
 		ob_end_clean();	
@@ -79,4 +73,27 @@
 		//echo "OK";
 	}
 
+	function checkMaxValue($id){
+		if($_POST[$id] != ""){
+			if(!is_numeric($_POST[$id])){
+				$jsone['result'] = "Fail";
+				$jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
+				echo json_encode($jsone);
+				exit;
+			}
+			if($_POST[$id]>65535){
+				$jsone['result'] = "Fail";
+				$jsone['message'] = "You have entered a over value on " . $id . ", it should be less than 65535";
+				echo json_encode($jsone);
+				exit;
+			}
+			if($_POST[$id]<0){
+				$jsone['result'] = "Fail";
+				$jsone['message'] = "You have entered a over value on " . $id . ", it should be more than 0";
+				echo json_encode($jsone);
+				exit;
+			}
+		}
+	}
+
 ?>

+ 48 - 46
EVSE/rootfs/var/www/set_network.php

@@ -89,9 +89,9 @@
 		<section class="envor-section">
 			<div class="container">
 				<div class="row">
-					<div class="col-lg-12">         
+					<div class="col-lg-12">
 						<div class="envor-sorting" id="faq-sorting">
-							<div class="envor-toggle">                
+							<div class="envor-toggle">
 								<!--Network Status-->
 								<article class="envor-sorting-item css">
 									<header><?php echo $lang->showWord("network_status"); ?><i class="fa fa-plus"></i></header>
@@ -339,39 +339,28 @@
 			request.open("POST", "set_network_action.php");
 
 			// POST 參數須使用 send() 發送
-			var data =  "InternetConn=" + document.getElementById("InternetConn").value +
-						"&FtpServer=" + document.getElementById("FtpServer").value +
+			var data =  "FtpServer=" + document.getElementById("FtpServer").value +
 						"&Eth0DhcpClient=" + document.getElementById("Eth0DhcpClient").value+
-						"&Eth0MacAddress=" + document.getElementById("Eth0MacAddress").value+
 						"&Eth0IpAddress=" + document.getElementById("Eth0IpAddress").value+
 						"&Eth0SubmaskAddress=" + document.getElementById("Eth0SubmaskAddress").value+
 						"&Eth0GatewayAddress=" + document.getElementById("Eth0GatewayAddress").value+
 						"&Eth1DhcpClient=" + document.getElementById("Eth1DhcpClient").value+
-						"&Eth1MacAddress=" + document.getElementById("Eth1MacAddress").value+
 						"&Eth1IpAddress=" + document.getElementById("Eth1IpAddress").value+
 						"&Eth1SubmaskAddress=" + document.getElementById("Eth1SubmaskAddress").value+
 						"&Eth1GatewayAddress=" + document.getElementById("Eth1GatewayAddress").value+
 						"&WifiMode=" + document.getElementById("WifiMode").value+
 						"&WifiSsid=" + document.getElementById("WifiSsid").value+
 						"&WifiPassword=" + document.getElementById("WifiPassword").value+
-						"&WifiRssi=" + document.getElementById("WifiRssi").value+
 						"&WifiDhcpServer=" + document.getElementById("WifiDhcpServer").value+
 						"&WifiDhcpClient=" + document.getElementById("WifiDhcpClient").value+
-						"&WifiMacAddress=" + document.getElementById("WifiMacAddress").value+
 						"&WifiIpAddress=" + document.getElementById("WifiIpAddress").value+
 						"&WifiSubmaskAddress=" + document.getElementById("WifiSubmaskAddress").value+
 						"&WifiGatewayAddress=" + document.getElementById("WifiGatewayAddress").value+
 						"&TelcomApn=" + document.getElementById("TelcomApn").value+
-						"&TelcomRssi=" + document.getElementById("TelcomRssi").value+
 						"&TelcomChapPapId=" + document.getElementById("TelcomChapPapId").value+
 						"&TelcomChapPapPwd=" + document.getElementById("TelcomChapPapPwd").value+
-						"&TelcomModemImei=" + document.getElementById("TelcomModemImei").value+
-						"&TelcomSimImsi=" + document.getElementById("TelcomSimImsi").value+
-						"&TelcomSimIccid=" + document.getElementById("TelcomSimIccid").value+
-						"&TelcomSimStatus=" + document.getElementById("TelcomSimStatus").value+
-						"&TelcomModemMode=" + document.getElementById("TelcomModemMode").value+
 						"&TelcomIpAddress=" + document.getElementById("TelcomIpAddress").value;
-			
+
 			// POST 請求必須設置表頭在 open() 下面,send() 上面
 			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 			request.send(data);
@@ -391,49 +380,62 @@
 			}
 		}
 	}
-	
+
 	function formCheck()
 	{
-		// var ChargerID = document.getElementById("new_id").value;
-		// var serverAddr = document.getElementById("new_server").value;
-		// var serverPort = document.getElementById("new_server_port").value;
-	 	 
-		 
-		 
-		// if(ChargerID.length < 6)
-		// {
-		  // alert("Charger ID format is not correct, ID length is required 6 atleast.");
-			  // ChargerID.focus();
-			  // return false;
-		// }
-		
-		// if(serverAddr.length <=0)
-		// {
-			// alert("Please check remote server address!");
-			  // serverAddr.focus();
-			  // return false;
-		// }
-		
-		// if((serverPort.value >65535) || (serverPort.value<0))
-		// {
-			// alert("Please check remote server port, it's must <= 65535!");
-			  // serverPort.focus();
-			  // return false;
-		// }
-		
+//		if(document.getElementById("Eth0IpAddress").value != ""){
+//			if(!ValidateIPaddress("Eth0IpAddress")) return false;
+//		}
+		if(document.getElementById("Eth0SubmaskAddress").value != ""){
+			if(!ValidateIPaddress("Eth0SubmaskAddress")) return false;
+		}
+		if(document.getElementById("Eth0GatewayAddress").value != ""){
+			if(!ValidateIPaddress("Eth0GatewayAddress")) return false;
+		}
+		if(document.getElementById("Eth1IpAddress").value != ""){
+			if(!ValidateIPaddress("Eth1IpAddress")) return false;
+		}
+		if(document.getElementById("Eth1SubmaskAddress").value != ""){
+			if(!ValidateIPaddress("Eth1SubmaskAddress")) return false;
+		}
+		if(document.getElementById("Eth1GatewayAddress").value != ""){
+			if(!ValidateIPaddress("Eth1GatewayAddress")) return false;
+		}
+		if(document.getElementById("WifiIpAddress").value != ""){
+			if(!ValidateIPaddress("WifiIpAddress")) return false;
+		}
+		if(document.getElementById("WifiSubmaskAddress").value != ""){
+			if(!ValidateIPaddress("WifiSubmaskAddress")) return false;
+		}
+		if(document.getElementById("WifiGatewayAddress").value != ""){
+			if(!ValidateIPaddress("WifiGatewayAddress")) return false;
+		}
+		if(document.getElementById("TelcomIpAddress").value != ""){
+			if(!ValidateIPaddress("TelcomIpAddress")) return false;
+		}
+
 		return true;
 	}
 
 	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 ValidateIPaddress(id) {
+		var ipaddress = document.getElementById(id).value;
+		if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) {
+			return true;
+		}
+		alert("You have entered an invalid IP address on " + id + "!")
+		document.getElementById(id).focus();
+		return false;
+	}
 </script>
 
 

+ 31 - 13
EVSE/rootfs/var/www/set_network_action.php

@@ -14,40 +14,44 @@
 	function create() {
 //		$json = json_decode(file_get_contents("charging.txt"), true);
 //		$json = string[];
-		$json['InternetConn']			= $_POST['InternetConn'];
 		$json['FtpServer']				= $_POST['FtpServer'];
 		$json['Eth0DhcpClient']			= $_POST['Eth0DhcpClient'];
-		$json['Eth0MacAddress']	 		= $_POST['Eth0MacAddress'];
 		$json['Eth0IpAddress']			= $_POST['Eth0IpAddress'];
 		$json['Eth0SubmaskAddress']		= $_POST['Eth0SubmaskAddress'];
 		$json['Eth0GatewayAddress']		= $_POST['Eth0GatewayAddress'];
 		$json['Eth1DhcpClient']			= $_POST['Eth1DhcpClient'];
-		$json['Eth1MacAddress']			= $_POST['Eth1MacAddress'];
 		$json['Eth1IpAddress']			= $_POST['Eth1IpAddress'];
 		$json['Eth1SubmaskAddress']		= $_POST['Eth1SubmaskAddress'];
 		$json['Eth1GatewayAddress']		= $_POST['Eth1GatewayAddress'];
 		$json['WifiMode']				= $_POST['WifiMode'];
 		$json['WifiSsid']				= $_POST['WifiSsid'];
 		$json['WifiPassword']			= $_POST['WifiPassword'];
-		$json['WifiRssi']				= (int)$_POST['WifiRssi'];
 		$json['WifiDhcpServer']			= $_POST['WifiDhcpServer'];
 		$json['WifiDhcpClient']			= $_POST['WifiDhcpClient'];
-		$json['WifiMacAddress']			= $_POST['WifiMacAddress'];
 		$json['WifiIpAddress']			= $_POST['WifiIpAddress'];
 		$json['WifiSubmaskAddress']		= $_POST['WifiSubmaskAddress'];
 		$json['WifiGatewayAddress']		= $_POST['WifiGatewayAddress'];
 		$json['TelcomApn']				= $_POST['TelcomApn'];
-		$json['TelcomRssi']				= (int)$_POST['TelcomRssi'];
 		$json['TelcomChapPapId']		= $_POST['TelcomChapPapId'];
 		$json['TelcomChapPapPwd']		= $_POST['TelcomChapPapPwd'];
-		$json['TelcomModemImei']		= $_POST['TelcomModemImei'];
-		$json['TelcomSimImsi']			= $_POST['TelcomSimImsi'];
-		$json['TelcomSimIccid']			= $_POST['TelcomSimIccid'];
-		$json['TelcomSimStatus']		= $_POST['TelcomSimStatus'];
-		$json['TelcomModemMode']		= $_POST['TelcomModemMode'];
 		$json['TelcomIpAddress']		= $_POST['TelcomIpAddress'];
-		var_dump($json);echo "\n\n";
-		echo json_encode($json);
+
+		checkip("Eth0IpAddress");
+		checkip("Eth0SubmaskAddress");
+		checkip("Eth0GatewayAddress");
+		checkip("Eth1IpAddress");
+		checkip("Eth1SubmaskAddress");
+		checkip("Eth1GatewayAddress");
+		checkip("WifiIpAddress");
+		checkip("WifiSubmaskAddress");
+		checkip("WifiGatewayAddress");
+		checkip("TelcomIpAddress");
+		
+//		var_dump($json);echo "\n\n";
+//		echo json_encode($json);
+		$jsone['result'] = "Success";
+		$jsone['message'] = $json;
+		echo json_encode($jsone);
 		
 		ob_start();
 		
@@ -62,4 +66,18 @@
 		//echo "OK";
 	}
 
+	function checkip($id){
+		$ip=$_POST[$id];
+		if($_POST[$id] != ""){
+			if(ip2long($ip)){
+				
+			}
+			else{
+				$jsone['result'] = "Fail";
+				$jsone['message'] = "You have entered an invalid IP address on " . $id;
+				echo json_encode($jsone);
+				exit;
+			}
+		}
+	}
 ?>

+ 5 - 42
EVSE/rootfs/var/www/set_system.php

@@ -92,11 +92,11 @@
 												<option value="3" <?php echo $obj->{'AcPhaseCount'}==3?"selected":""?>>Three phase</option>
 											</select>
 										</div>
-										<div class="form-group" style="display:<?php echo $am111;?>">
+<?php /*										<div class="form-group" style="display:<?php echo $am111;?>">
 											<label>System Status</label>
 											<input type="text" readonly class="form-control" placeholder="<?php echo $SystemStatus;?>">
 											<input type="hidden" name="SystemStatus" id="SystemStatus" value="<?php echo $SystemStatus;?>">
-										</div>
+										</div>*/?>
 										<div class="form-group" style="display:<?php echo $am111;?>">
 											<label>Factory Configuration</label>
 											<select class="form-control" id="FactoryConfiguration" name="FactoryConfiguration">
@@ -371,50 +371,13 @@
 			request.open("POST", "set_system_action.php");
 
 			// POST 參數須使用 send() 發送
-			var data =  "ModelName=" + document.getElementById("ModelName").value +
-						"&SerialNumber=" + document.getElementById("SerialNumber").value +
-						"&SystemId=" + document.getElementById("SystemId").value+
+			var data =  "SystemId=" + document.getElementById("SystemId").value+
 						"&SystemDateTime=" + document.getElementById("SystemDateTime").value+
-						"&SystemStatus=" + document.getElementById("SystemStatus").value+
+						"&AcPhaseCount=" + document.getElementById("AcPhaseCount").value+
 						"&FactoryConfiguration=" + document.getElementById("FactoryConfiguration").value+
 						"&AuthorisationMode=" + document.getElementById("AuthorisationMode").value+
 						"&DefaultLanguage=" + document.getElementById("DefaultLanguage").value+
-						"&InputVoltageR=" + document.getElementById("InputVoltageR").value+
-						"&InputVoltageS=" + document.getElementById("InputVoltageS").value+
-						"&InputVoltageT=" + document.getElementById("InputVoltageT").value+
-						"&SystemFanRotaSpeed=" + document.getElementById("SystemFanRotaSpeed").value+
-						"&PsuFanRotaSpeed=" + document.getElementById("PsuFanRotaSpeed").value+
-						"&RfidCardNumEndian=" + document.getElementById("RfidCardNumEndian").value+
-						"&AuxPower5V=" + document.getElementById("AuxPower5V").value+
-						"&AuxPower12V=" + document.getElementById("AuxPower12V").value+
-						"&AuxPower24V=" + document.getElementById("AuxPower24V").value+
-						"&AuxPower48V=" + document.getElementById("AuxPower48V").value+
-						"&CsuHwRev=" + document.getElementById("CsuHwRev").value+
-						"&CsuBootLoadFwRev=" + document.getElementById("CsuBootLoadFwRev").value+
-						"&CsuKernelFwRev=" + document.getElementById("CsuKernelFwRev").value+
-						"&CsuRootFsFwRev=" + document.getElementById("CsuRootFsFwRev").value+
-						"&CsuPrimFwRev=" + document.getElementById("CsuPrimFwRev").value+
-						"&LcmHwRev=" + document.getElementById("LcmHwRev").value+
-						"&LcmFwRev=" + document.getElementById("LcmFwRev").value+
-						"&PsuHwRev=" + document.getElementById("PsuHwRev").value+
-						"&PsuPrimFwRev=" + document.getElementById("PsuPrimFwRev").value+
-						"&PsuSecFwRev=" + document.getElementById("PsuSecFwRev").value+
-						"&AuxPwrHwRev=" + document.getElementById("AuxPwrHwRev").value+
-						"&AuxPwrFwRev=" + document.getElementById("AuxPwrFwRev").value+
-						"&FanModuleHwRev=" + document.getElementById("FanModuleHwRev").value+
-						"&FanModuleFwRev=" + document.getElementById("FanModuleFwRev").value+
-						"&RelayModuleHwRev=" + document.getElementById("RelayModuleHwRev").value+
-						"&RelayModuleFwRev=" + document.getElementById("RelayModuleFwRev").value+
-						"&TelcomModemFwRev=" + document.getElementById("TelcomModemFwRev").value+
-						"&SystemAmbientTemp=" + document.getElementById("SystemAmbientTemp").value+
-						"&SystemCriticalTemp=" + document.getElementById("SystemCriticalTemp").value+
-						"&CcsConnectorTemp=" + document.getElementById("CcsConnectorTemp").value+
-						"&PsuAmbientTemp=" + document.getElementById("PsuAmbientTemp").value+
-						"&AcPlugInTimes=" + document.getElementById("AcPlugInTimes").value+
-						"&GbPlugInTimes=" + document.getElementById("GbPlugInTimes").value+
-						"&Ccs1PlugInTimes=" + document.getElementById("Ccs1PlugInTimes").value+
-						"&Ccs2PlugInTimes=" + document.getElementById("Ccs2PlugInTimes").value+
-						"&ChademoPlugInTimes=" + document.getElementById("ChademoPlugInTimes").value;
+						"&RfidCardNumEndian=" + document.getElementById("RfidCardNumEndian").value;
 			
 			// POST 請求必須設置表頭在 open() 下面,send() 上面
 			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

+ 21 - 39
EVSE/rootfs/var/www/set_system_action.php

@@ -13,51 +13,27 @@
 	// 新建員工
 	function create() {
 //		$json = json_decode(file_get_contents("system.txt"), true);
-		$json['ModelName']				= $_POST['ModelName'];
-		$json['SerialNumber'] 			= $_POST["SerialNumber"];
 		$json['SystemId']				= $_POST["SystemId"];
 		$json['SystemDateTime'] 		= $_POST['SystemDateTime'];
 		$json['AcPhaseCount'] 			= $_POST['AcPhaseCount'];
-		$json['SystemStatus']			= $_POST['SystemStatus'];
 		$json['FactoryConfiguration']	= $_POST['FactoryConfiguration'];
 		$json['AuthorisationMode']	 	= $_POST['AuthorisationMode'];
 		$json['DefaultLanguage']		= chr($_POST['DefaultLanguage']);
-		$json['InputVoltageR']			= $_POST['InputVoltageR'];
-		$json['InputVoltageS']			= $_POST['InputVoltageS'];
-		$json['InputVoltageT']			= $_POST['InputVoltageT'];
-		$json['SystemFanRotaSpeed']		= $_POST['SystemFanRotaSpeed'];
-		$json['PsuFanRotaSpeed']		= $_POST['PsuFanRotaSpeed'];
 		$json['RfidCardNumEndian']		= $_POST['RfidCardNumEndian'];
-/*		$json['AuxPower5V']				= $_POST["AuxPower5V"];
-		$json['AuxPower12V']			= $_POST["AuxPower12V"];
-		$json['AuxPower24V']			= $_POST['AuxPower24V'];
-		$json['AuxPower48V']			= $_POST['AuxPower48V'];
-		$json['CsuHwRev']				= $_POST['CsuHwRev'];
-		$json['CsuBootLoadFwRev']		= $_POST['CsuBootLoadFwRev'];
-		$json['CsuKernelFwRev']			= $_POST['CsuKernelFwRev'];
-		$json['CsuRootFsFwRev']			= $_POST['CsuRootFsFwRev'];
-		$json['CsuPrimFwRev']			= $_POST['CsuPrimFwRev'];
-		$json['LcmHwRev']				= $_POST['LcmHwRev'];
-		$json['LcmFwRev']				= $_POST['LcmFwRev'];
-		$json['PsuHwRev']				= $_POST['PsuHwRev'];
-		$json['PsuPrimFwRev']			= $_POST['PsuPrimFwRev'];
-		$json['PsuSecFwRev']			= $_POST["PsuSecFwRev"];
-		$json['AuxPwrHwRev']			= $_POST["AuxPwrHwRev"];
-		$json['AuxPwrFwRev']			= $_POST['AuxPwrFwRev'];
-		$json['FanModuleHwRev']			= $_POST['FanModuleHwRev'];
-		$json['FanModuleFwRev']			= $_POST['FanModuleFwRev'];
-		$json['RelayModuleHwRev']		= $_POST['RelayModuleHwRev'];
-		$json['RelayModuleFwRev']		= $_POST['RelayModuleFwRev'];
-		$json['TelcomModemFwRev']		= $_POST['TelcomModemFwRev'];
-		$json['SystemAmbientTemp']		= $_POST['SystemAmbientTemp'];
-		$json['SystemCriticalTemp']		= $_POST['SystemCriticalTemp'];
-		$json['CcsConnectorTemp']		= $_POST['CcsConnectorTemp'];
-		$json['PsuAmbientTemp']			= $_POST['PsuAmbientTemp'];
-		$json['AcPlugInTimes']			= $_POST['AcPlugInTimes'];
-		$json['GbPlugInTimes']			= $_POST["GbPlugInTimes"];
-		$json['Ccs1PlugInTimes']		= $_POST["Ccs1PlugInTimes"];
-		$json['Ccs2PlugInTimes']		= $_POST['Ccs2PlugInTimes'];
-		$json['ChademoPlugInTimes'] 	= $_POST['ChademoPlugInTimes'];*/
+		
+//		var_dump($json);echo "\n\n";
+//		echo json_encode($json);
+		if($_POST['SystemDateTime'] != ""){
+			if(!validateDate($_POST['SystemDateTime'])){
+			$jsone['result'] = "Fail";
+			$jsone['message'] = "SystemDateTime format or content error, fill it with 'yyyy-mm-dd hh:ii:ss";
+			echo json_encode($jsone);
+			return false;
+			}
+		}
+		$jsone['result'] = "Success";
+		$jsone['message'] = $json;
+		echo json_encode($jsone);
 		//echo json_encode($json);
 		//file_put_contents("system.dat", json_encode($json));
 		
@@ -87,8 +63,14 @@
 		exec("'./WebService' '1' '".$str_json."'",$output,$return_var);
 //		copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
 		ob_end_clean();	
-		print_r($output);
+//		print_r($output);
 		//echo "OK";
 	}
+	
+	function validateDate($date, $format = 'Y-m-d H:i:s')
+	{
+		$d = DateTime::createFromFormat($format, $date);
+		return $d && $d->format($format) == $date;
+	}
 
 ?>

+ 1 - 0
EVSE/rootfs/var/www/switch_lang.php

@@ -20,6 +20,7 @@
 		$json['web_lang'] = $_GET['lang'];
 			
 		file_put_contents("settings", json_encode($json));
+		exec("cp settings /Storage/settings");
 		shell_exec('sync;sync;sync');
 		
 		header('Location: ' . $_SERVER['HTTP_REFERER']);