浏览代码

2022-10-05

Actions:
1. Webservice modify for upgrade to PHP8

Files:
1. EVSE/rootfs/var/www/set_backend_action.php
ct_chen 2 年之前
父节点
当前提交
20cb9a1924
共有 1 个文件被更改,包括 201 次插入200 次删除
  1. 201 200
      EVSE/rootfs/var/www/set_backend_action.php

+ 201 - 200
EVSE/rootfs/var/www/set_backend_action.php

@@ -1,200 +1,201 @@
-<?php
-	// 設置資料類型 json,編碼格式 utf-8
-	header('Content-Type: application/json; charset=UTF-8');
-	
-	// 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
-	// $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
-	if ($_SERVER['REQUEST_METHOD'] == "GET") {
-		create();
-	} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
-		create();
-	}
-
-	// 新建員工
-	function create() {
-		$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($_REQUEST['OcppServerURL']!=""){
-			$json['OcppServerURL']				= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppServerURL'])))));
-			if(!preg_match($pattern, $json['OcppServerURL'])){
-				$jsone['result'] = "Fail";
-				$jsone['message'] = "OcppServerURL format error, fill it with 'ws://' or 'wss://'";
-				echo json_encode($jsone);
-				return false;
-			}
-		}
-		if($_REQUEST['MaintainServerURL']!=""){
-			$json['MaintainServerURL']			= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['MaintainServerURL'])))));
-			if(!preg_match($pattern, $json['MaintainServerURL'])){
-				$jsone['result'] = "Fail";
-				$jsone['message'] = "MaintainServerURL format error, fill it with 'ws://' or 'wss://'";
-				echo json_encode($jsone);
-				return false;
-			}
-		}
-		checkValue("OfflinePolicy");
-		checkLength("ChargeBoxId",25);
-		checkLength("chargePointVendor",20);
-		if(isset($_REQUEST['BackendConnTimeout'])){
-			$json['BackendConnTimeout']			= (int)$_REQUEST['BackendConnTimeout'];
-		}
-		if(isset($_REQUEST['OfflinePolicy'])){
-			$json['OfflinePolicy']				= (int)$_REQUEST['OfflinePolicy'];
-		}
-		if(isset($_REQUEST['OfflineMaxChargeEnergy'])){
-			$json['OfflineMaxChargeEnergy']		= (int)$_REQUEST['OfflineMaxChargeEnergy'];
-		}
-		if(isset($_REQUEST['OfflineMaxChargeDuration'])){
-			$json['OfflineMaxChargeDuration']	= (int)$_REQUEST['OfflineMaxChargeDuration'];
-		}
-		if(isset($_REQUEST['OcppServerURL'])){
-			$json['OcppServerURL']				= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppServerURL'])))));
-		}
-		if(isset($_REQUEST['MaintainServerURL'])){
-			$json['MaintainServerURL']			= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['MaintainServerURL'])))));
-		}
-		if(isset($_REQUEST['ChargeBoxId'])){
-			$json['ChargeBoxId']				= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['ChargeBoxId'])))));
-		}
-		if(isset($_REQUEST['chargePointVendor'])){
-			$json['chargePointVendor']			= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['chargePointVendor'])))));
-		}
-		if(isset($_REQUEST['OcppSecurityProfile'])){
-			checkValue("OcppSecurityProfile");
-			$json['OcppSecurityProfile']		= (int)$_REQUEST['OcppSecurityProfile'];
-		}
-		if(isset($_REQUEST['OcppSecurityPassword'])){
-			$json['OcppSecurityPassword']		= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppSecurityPassword'])))));
-		}
-		if(isset($_REQUEST['MaintainServerSecurityProfile'])){
-			checkValue("MaintainServerSecurityProfile");
-			$json['MaintainServerSecurityProfile']		= (int)$_REQUEST['MaintainServerSecurityProfile'];
-		}
-		if(isset($_REQUEST['MaintainServerSecurityPassword'])){
-			$json['MaintainServerSecurityPassword']		= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['MaintainServerSecurityPassword'])))));
-		}
-		if(isset($_REQUEST['isEnableLocalPowerSharging'])){
-			checkValue("isEnableLocalPowerSharging");
-			$json['isEnableLocalPowerSharging']	= (int)$_REQUEST['isEnableLocalPowerSharging'];
-		}
-		if(isset($_REQUEST['PowerSharingCapacity'])){
-			$json['PowerSharingCapacity']	= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['PowerSharingCapacity'])))));
-		}
-		if(isset($_REQUEST['PowerSharingServerIP'])){
-			$json['PowerSharingServerIP']	= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['PowerSharingServerIP'])))));
-		}
-		if(isset($_REQUEST['OcppReceiptrURL'])){
-			$json['OcppReceiptrURL']			= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppReceiptrURL'])))));
-		}
-		if(isset($_REQUEST['isEnableTTIA'])){
-			checkValue("isEnableTTIA");
-			$json['isEnableTTIA']				= (int)$_REQUEST['isEnableTTIA'];
-		}
-		if(isset($_REQUEST['server_addr'])){
-			$json['server_addr']				= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['server_addr'])))));
-		}
-		if(isset($_REQUEST['server_port'])){
-			isNumeric("server_port",65535);
-			$json['server_port']				= (int)$_REQUEST['server_port'];
-		}
-		if(isset($_REQUEST['busVenderId'])){
-			isNumeric("busVenderId",65535);
-			$json['busVenderId']				= (int)$_REQUEST['busVenderId'];
-		}
-		if(isset($_REQUEST['EquipmentProvider'])){
-			checkLength("EquipmentProvider",15);
-			$json['EquipmentProvider']			= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['EquipmentProvider'])))));
-		}
-		if(isset($_REQUEST['TransportationCompanyNo'])){
-			isNumeric("TransportationCompanyNo",255);
-			$json['TransportationCompanyNo']	= (int)$_REQUEST['TransportationCompanyNo'];
-		}
-		if(isset($_REQUEST['TTIAChargeBoxId'])){
-			isNumeric("TTIAChargeBoxId",255);
-			$json['TTIAChargeBoxId']			= (int)$_REQUEST['TTIAChargeBoxId'];
-		}
-		if(isset($_REQUEST['evseStation'])){
-			checkLength("evseStation",15);
-			$json['evseStation']				= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['evseStation'])))));
-		}
-		$fCount = count($_FILES['private_key']['name']);
-		if($fCount>0){
-			if ($_FILES["private_key"]["error"] > 0)
-			{
-				echo "Return Code: " . $_FILES["private_key"]["error"] . "<br />";
-			}
-			sleep(1);
-			move_uploaded_file($_FILES["private_key"]["tmp_name"],"/Storage/OCPP/certCP.key");
-		}
-		$fCount = count($_FILES['certificate']['name']);
-		if($fCount>0){
-			if ($_FILES["certificate"]["error"] > 0)
-			{
-				echo "Return Code: " . $_FILES["certificate"]["error"] . "<br />";
-			}
-			sleep(1);
-			move_uploaded_file($_FILES["certificate"]["tmp_name"],"/Storage/OCPP/certCP.pem");
-		}
-
-//		ob_start();
-		
-		shell_exec('sync;sync;sync');
-		chdir("/root");
-		$str_json=json_encode($json);//var_dump($str_json);
-		exec("'./WebService' '4' '".$str_json."'",$output,$return_var);
-		 if(count($output)!=0){
-			 $jsone['result'] = "Success";
-			 $jsone['message'] = $json;
-			 echo json_encode($jsone);
-			 exit;
-		 }
-		 else{
-			 $jsone['result'] = "Error";
-			 $jsone['message'] = "Something went wrong on machine";
-			 echo json_encode($jsone);
-			 return false;
-			 exit;
-		 }
-//		ob_end_clean();	
-	}
-
-	function checkValue($id){
-		if($_REQUEST[$id] != ""){
-			if(strlen($_REQUEST[$id])!=1){
-					$jsone['result'] = "Fail";
-					$jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
-					echo json_encode($jsone);
-					exit;
-			}
-			if(!is_numeric($_REQUEST[$id])){
-					$jsone['result'] = "Fail";
-					$jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
-					echo json_encode($jsone);
-					exit;
-			}
-		}
-	}
-	function checkLength($id,$value){
-		if(strlen($_REQUEST[$id])>$value){
-				$jsone['result'] = "Fail";
-				$jsone['message'] = "Length of " . $id . " should be less than ".$value+"(Chinese 5 words)";
-				echo json_encode($jsone);
-				exit;
-		}
-	}
-	function isNumeric($id,$value){
-		if($_REQUEST[$id] != ""){
-			if(!is_numeric($_REQUEST[$id])){
-					$jsone['result'] = "Fail";
-					$jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
-					echo json_encode($jsone);
-					exit;
-			}
-			if($_REQUEST[$id]>$value){
-					$jsone['result'] = "Fail";
-					$jsone['message'] = "Value of " . $id . " should be less than ".$value;
-					echo json_encode($jsone);
-					exit;
-			}
-		}
-	}
-?>
+<?php
+	// 設置資料類型 json,編碼格式 utf-8
+	header('Content-Type: application/json; charset=UTF-8');
+	
+	// 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
+	// $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
+	if ($_SERVER['REQUEST_METHOD'] == "GET") {
+		create();
+	} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
+		create();
+	}
+
+	// 新建員工
+	function create() {
+		$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($_REQUEST['OcppServerURL']!=""){
+			$json['OcppServerURL']				= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppServerURL'])))));
+			if(!preg_match($pattern, $json['OcppServerURL'])){
+				$jsone['result'] = "Fail";
+				$jsone['message'] = "OcppServerURL format error, fill it with 'ws://' or 'wss://'";
+				echo json_encode($jsone);
+				return false;
+			}
+		}
+		if($_REQUEST['MaintainServerURL']!=""){
+			$json['MaintainServerURL']			= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['MaintainServerURL'])))));
+			if(!preg_match($pattern, $json['MaintainServerURL'])){
+				$jsone['result'] = "Fail";
+				$jsone['message'] = "MaintainServerURL format error, fill it with 'ws://' or 'wss://'";
+				echo json_encode($jsone);
+				return false;
+			}
+		}
+		checkValue("OfflinePolicy");
+		checkLength("ChargeBoxId",25);
+		checkLength("chargePointVendor",20);
+		if(isset($_REQUEST['BackendConnTimeout'])){
+			$json['BackendConnTimeout']			= (int)$_REQUEST['BackendConnTimeout'];
+		}
+		if(isset($_REQUEST['OfflinePolicy'])){
+			$json['OfflinePolicy']				= (int)$_REQUEST['OfflinePolicy'];
+		}
+		if(isset($_REQUEST['OfflineMaxChargeEnergy'])){
+			$json['OfflineMaxChargeEnergy']		= (int)$_REQUEST['OfflineMaxChargeEnergy'];
+		}
+		if(isset($_REQUEST['OfflineMaxChargeDuration'])){
+			$json['OfflineMaxChargeDuration']	= (int)$_REQUEST['OfflineMaxChargeDuration'];
+		}
+		if(isset($_REQUEST['OcppServerURL'])){
+			$json['OcppServerURL']				= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppServerURL'])))));
+		}
+		if(isset($_REQUEST['MaintainServerURL'])){
+			$json['MaintainServerURL']			= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['MaintainServerURL'])))));
+		}
+		if(isset($_REQUEST['ChargeBoxId'])){
+			$json['ChargeBoxId']				= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['ChargeBoxId'])))));
+		}
+		if(isset($_REQUEST['chargePointVendor'])){
+			$json['chargePointVendor']			= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['chargePointVendor'])))));
+		}
+		if(isset($_REQUEST['OcppSecurityProfile'])){
+			checkValue("OcppSecurityProfile");
+			$json['OcppSecurityProfile']		= (int)$_REQUEST['OcppSecurityProfile'];
+		}
+		if(isset($_REQUEST['OcppSecurityPassword'])){
+			$json['OcppSecurityPassword']		= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppSecurityPassword'])))));
+		}
+		if(isset($_REQUEST['MaintainServerSecurityProfile'])){
+			checkValue("MaintainServerSecurityProfile");
+			$json['MaintainServerSecurityProfile']		= (int)$_REQUEST['MaintainServerSecurityProfile'];
+		}
+		if(isset($_REQUEST['MaintainServerSecurityPassword'])){
+			$json['MaintainServerSecurityPassword']		= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['MaintainServerSecurityPassword'])))));
+		}
+		if(isset($_REQUEST['isEnableLocalPowerSharging'])){
+			checkValue("isEnableLocalPowerSharging");
+			$json['isEnableLocalPowerSharging']	= (int)$_REQUEST['isEnableLocalPowerSharging'];
+		}
+		if(isset($_REQUEST['PowerSharingCapacity'])){
+			$json['PowerSharingCapacity']	= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['PowerSharingCapacity'])))));
+		}
+		if(isset($_REQUEST['PowerSharingServerIP'])){
+			$json['PowerSharingServerIP']	= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['PowerSharingServerIP'])))));
+		}
+		if(isset($_REQUEST['OcppReceiptrURL'])){
+			$json['OcppReceiptrURL']			= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['OcppReceiptrURL'])))));
+		}
+		if(isset($_REQUEST['isEnableTTIA'])){
+			checkValue("isEnableTTIA");
+			$json['isEnableTTIA']				= (int)$_REQUEST['isEnableTTIA'];
+		}
+		if(isset($_REQUEST['server_addr'])){
+			$json['server_addr']				= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['server_addr'])))));
+		}
+		if(isset($_REQUEST['server_port'])){
+			isNumeric("server_port",65535);
+			$json['server_port']				= (int)$_REQUEST['server_port'];
+		}
+		if(isset($_REQUEST['busVenderId'])){
+			isNumeric("busVenderId",65535);
+			$json['busVenderId']				= (int)$_REQUEST['busVenderId'];
+		}
+		if(isset($_REQUEST['EquipmentProvider'])){
+			checkLength("EquipmentProvider",15);
+			$json['EquipmentProvider']			= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['EquipmentProvider'])))));
+		}
+		if(isset($_REQUEST['TransportationCompanyNo'])){
+			isNumeric("TransportationCompanyNo",255);
+			$json['TransportationCompanyNo']	= (int)$_REQUEST['TransportationCompanyNo'];
+		}
+		if(isset($_REQUEST['TTIAChargeBoxId'])){
+			isNumeric("TTIAChargeBoxId",255);
+			$json['TTIAChargeBoxId']			= (int)$_REQUEST['TTIAChargeBoxId'];
+		}
+		if(isset($_REQUEST['evseStation'])){
+			checkLength("evseStation",15);
+			$json['evseStation']				= str_replace("&amp;","&",str_replace("&quot;",'"',str_replace("&#039;","'",str_replace("&lt;","<",str_replace("&gt;",">",$_REQUEST['evseStation'])))));
+		}
+//			$fCount = count($_FILES['private_key']['name']);
+		$fCount = empty($_FILES['private_key']['tmp_name'][0]);
+		if($fCount!=1){
+			if ($_FILES["private_key"]["error"] > 0)
+			{
+				echo "Return Code: " . $_FILES["private_key"]["error"] . "<br />";
+			}
+			sleep(1);
+			move_uploaded_file($_FILES["private_key"]["tmp_name"],"/Storage/OCPP/certCP.key");
+		}
+//			$fCount = count($_FILES['certificate']['name']);
+		$fCount = empty($_FILES['certificate']['tmp_name'][0]);
+		if($fCount!=1){
+			if ($_FILES["certificate"]["error"] > 0)
+			{
+				echo "Return Code: " . $_FILES["certificate"]["error"] . "<br />";
+			}
+			sleep(1);
+			move_uploaded_file($_FILES["certificate"]["tmp_name"],"/Storage/OCPP/certCP.pem");
+		}
+//		ob_start();
+		
+		shell_exec('sync;sync;sync');
+		chdir("/root");
+		$str_json=json_encode($json);//var_dump($str_json);
+		exec("'./WebService' '4' '".$str_json."'",$output,$return_var);
+		 if(count($output)!=0){
+			 $jsone['result'] = "Success";
+			 $jsone['message'] = $json;
+			 echo json_encode($jsone);
+			 exit;
+		 }
+		 else{
+			 $jsone['result'] = "Error";
+			 $jsone['message'] = "Something went wrong on machine";
+			 echo json_encode($jsone);
+			 return false;
+			 exit;
+		 }
+//		ob_end_clean();	
+	}
+
+	function checkValue($id){
+		if($_REQUEST[$id] != ""){
+			if(strlen($_REQUEST[$id])!=1){
+					$jsone['result'] = "Fail";
+					$jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
+					echo json_encode($jsone);
+					exit;
+			}
+			if(!is_numeric($_REQUEST[$id])){
+					$jsone['result'] = "Fail";
+					$jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
+					echo json_encode($jsone);
+					exit;
+			}
+		}
+	}
+	function checkLength($id,$value){
+		if(strlen($_REQUEST[$id])>$value){
+				$jsone['result'] = "Fail";
+				$jsone['message'] = "Length of " . $id . " should be less than ".$value+"(Chinese 5 words)";
+				echo json_encode($jsone);
+				exit;
+		}
+	}
+	function isNumeric($id,$value){
+		if($_REQUEST[$id] != ""){
+			if(!is_numeric($_REQUEST[$id])){
+					$jsone['result'] = "Fail";
+					$jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
+					echo json_encode($jsone);
+					exit;
+			}
+			if($_REQUEST[$id]>$value){
+					$jsone['result'] = "Fail";
+					$jsone['message'] = "Value of " . $id . " should be less than ".$value;
+					echo json_encode($jsone);
+					exit;
+			}
+		}
+	}
+?>