Browse Source

2019-09-21 / ct_chen

Actions:
1. 配合主程式將更新功能改回只能單一檔案待更新
2. 網頁增加修改登入帳號的密碼

Files:
1. EVSE/Modularization/WebService.c
2. EVSE/rootfs/var/www/*
ct_chen 5 years ago
parent
commit
e5a17c64a3

+ 7 - 7
EVSE/Modularization/WebService.c

@@ -783,17 +783,17 @@ int main(int argc, char *argv[]) {
 		char cmd[100];
 		jobj=json_object_new_object();
 		//system
-		//if((char)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == '0'){
-		strcpy((char *)&ShmSysConfigAndInfo->SysInfo.FirmwareUpdate, "1");
-		Result = json_object_new_string("success");
-		Message = json_object_new_string("file is uploaded");
-		//}
-		/*else{
+		if((char)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == '0'){
+			strcpy((char *)&ShmSysConfigAndInfo->SysInfo.FirmwareUpdate, "1");
+			Result = json_object_new_string("success");
+			Message = json_object_new_string("file is uploaded");
+		}
+		else{
 			sprintf(cmd,"rm /mnt/%s",argv[2]);
 			system(cmd);
 			Result = json_object_new_string("error");
 			Message = json_object_new_string("machine is busy");
-		}*/
+		}
 		json_object_object_add(jobj,"Result",Result);
 		json_object_object_add(jobj,"Message",Message);
 		printf("%s\n", json_object_to_json_string(jobj));

+ 15 - 9
EVSE/rootfs/var/www/head.php

@@ -7,18 +7,18 @@
 	ini_set('error_reporting', E_ERROR | E_WARNING | E_PARSE);
 	$json = json_decode(file_get_contents("settings"), true);
 	
-//	include 'valid.php';
-//	$valid = new Valid;
+	include 'valid.php';
+	$valid = new Valid;
 	//=======================================
 	// Auth
 	//=======================================
-	// if(!$valid->validUser($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))  
-	// {
-		// header('WWW-Authenticate: Basic realm="My Realm"');
-		// header('HTTP/1.0 401 Unauthorized');
-		// echo 'Text to send if user hits Cancel button';
-		// exit;
-	// } 
+	 if(!$valid->validUser($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))  
+	 {
+		 header('WWW-Authenticate: Basic realm="My Realm"');
+		 header('HTTP/1.0 401 Unauthorized');
+		 echo 'Text to send if user hits Cancel button';
+		 exit;
+	} 
 
 	include 'lang.php';
 	$selected1="";
@@ -215,6 +215,9 @@
 						<li>
 						  <a href="log_download.php"><?php echo $lang->showWord("log_download"); ?></a>
 						</li>
+						<li>
+						  <a href="set_passwd.php"><?php echo $lang->showWord("passwd"); ?></a>
+						</li>
 					</ul> 
 				</li>
 				<li<?php echo ($tag_header=='language'?' class="active"':''); ?>>
@@ -326,6 +329,9 @@
 						<li>
 						  <a href="log_download.php"><?php echo $lang->showWord("log_download"); ?></a>
 						</li>
+						<li>
+						  <a href="set_passwd.php"><?php echo $lang->showWord("passwd"); ?></a>
+						</li>
                       </ul>
                     </li>
 					<li<?php echo ($tag_header=='language'?' class="active"':''); ?>>

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

@@ -289,7 +289,7 @@
 									</section>
 								</article>
 								<!--Bluetooth Module-->
-								<article class="envor-sorting-item css">
+<?php /*								<article class="envor-sorting-item css">
 									<header><?php echo $lang->showWord("bluetooth_module"); ?><i class="fa fa-plus"></i></header>
 									<section>
 										<div class="form-group" style="display:<?php echo $am101;?>">
@@ -313,7 +313,7 @@
 											<input type="hidden" name="isRequestStop" id="isRequestStop" value="<?php echo $obj->{'isRequestStop'};?>">
 										</div>
 									</section>
-								</article>
+								</article>  */?>
 								<article class="envor-sorting-item css">
 									<div align="center"><button id="save"><?php echo $lang->showWord("set")?></button></div>
 								</article>

+ 124 - 0
EVSE/rootfs/var/www/set_passwd.php

@@ -0,0 +1,124 @@
+<?php
+	ini_set('error_reporting', E_ALL | E_STRICT);
+	$tag_header = 'other';
+	include 'head.php';
+?>
+
+	<div class="envor-content">
+		<!--
+		Page Title start
+		//-->
+		<section class="envor-page-title-1" data-stellar-background-ratio="0.5">
+			<div class="container">
+				<div class="row">
+					<div class="col-lg-9 col-md-9 col-sm-9">
+						<h1><?php echo $lang->showWord("passwd"); ?></h1>
+					</div>
+				</div>
+			</div>
+		<!--
+		Page Title end
+		//-->
+		</section>
+		<!--
+		Main Content start
+		//-->
+		<section class="envor-section">
+			<div class="container">
+				<div class="row">
+					<div class="col-lg-12">
+						<div class="envor-sorting" id="faq-sorting">
+							<div class="envor-toggle">
+								<!--English-->
+								<article class="envor-sorting-item css">
+									<header><?php echo $lang->showWord("passwd"); ?><i class="fa fa-plus"></i></header>
+									<section>
+										<div class="form-group">
+											<label><?php echo $lang->showWord("passwd_keyin"); ?></label>
+											<input type="text" name="passwd1" id="passwd1" class="form-control">
+										</div>
+										<div class="form-group">
+											<label><?php echo $lang->showWord("passwd_keyin2"); ?></label>
+											<input type="text" name="passwd2" id="passwd2" class="form-control">
+										</div>
+									</section>
+								</article>
+								<article class="envor-sorting-item css">
+									<div align="center"><button id="save"><?php echo $lang->showWord("set")?></button></div>
+								</article>
+							</div>
+						</div>
+					</div>
+				</div>
+			</div>
+		</section>
+	</div>
+
+<?php
+	include 'foot.php';
+?>
+
+<script type="text/JavaScript">
+	
+	document.getElementById("save").onclick = function() {
+		// 發送 Ajax 查詢請求並處理
+		var request = new XMLHttpRequest();
+		request.open("POST", "set_passwd_action.php");
+		
+		if(formCheck())
+		{
+			// POST 參數須使用 send() 發送
+			var data =  "passwd=" + document.getElementById("passwd1").value+
+			"&user=<?php echo $_SERVER['PHP_AUTH_USER'];?>";
+			// POST 請求必須設置表頭在 open() 下面,send() 上面
+			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+			request.send(data);
+			
+			request.onreadystatechange = function() {
+				// 伺服器請求完成
+				if (request.readyState === 4) {
+					// 伺服器回應成功
+					if (request.status === 200) {
+						//window.location.replace('/set_passwd.php');
+						alert("done");
+					} else {
+						alert("發生錯誤" + request.status);
+					}
+				}
+			}	
+		}		
+	}
+	
+	
+	function formCheck()
+	{
+		if(document.getElementById("passwd1").value != document.getElementById("passwd2").value)
+		{
+			alert("Password is different!");
+			return false;
+		}
+		else
+		{
+			if( confirm("Are you sure to set new password?") == 1 )
+				return true;
+			else
+				return false;
+		}
+	}
+
+	function isNumberKey(evt)
+	{
+		var charCode = (evt.which) ? evt.which : event.keyCode
+		
+		if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
+			return false;
+		
+		return true;
+	}
+	
+	
+	
+</script>
+
+
+</html>

+ 27 - 0
EVSE/rootfs/var/www/set_passwd_action.php

@@ -0,0 +1,27 @@
+<?php
+	header('Content-Type: application/json; charset=UTF-8');
+	
+	if ($_SERVER['REQUEST_METHOD'] == "GET") {
+		create();
+	} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
+		create();
+	}
+
+	// 
+	function create() {
+		$json = json_decode(file_get_contents("valid_info"), true);
+		/*
+		$json['admin'] 			= md5($_REQUEST['passwd']);
+		$json['superPhihong'] 	= md5('1231231238');
+		*/
+		$json[$_REQUEST['user']]=md5($_REQUEST['passwd']);
+		file_put_contents("valid_info", json_encode($json));
+		exec("cp valid_info /Storage/valid_info");
+//		shell_exec('sync;sync;sync');
+//		session_destroy();
+//		session_unset($_SESSION['session_id']);
+
+		echo "OK";
+	}
+
+?>

+ 24 - 0
EVSE/rootfs/var/www/valid.php

@@ -0,0 +1,24 @@
+<?php
+	class Valid	{
+		var $isSuccess;
+			
+		function validUser($user, $passwd)
+		{
+			if(file_exists("/Storage/valid_info")){
+				exec("cp /Storage/valid_info valid_info");
+			}
+			$array = json_decode(file_get_contents("valid_info"), true);
+			$isSuccess = false;
+			
+			foreach ($array as $key => $value) {				 
+				if(($user == $key) && (md5($passwd) == $value))
+				{
+					$isSuccess = true;
+					continue;
+				}	 					 
+			}
+		
+			return $isSuccess;
+		}
+	}
+?>

+ 1 - 0
EVSE/rootfs/var/www/valid_info

@@ -0,0 +1 @@
+{"admin":"528a82ee4b7956c31150a2e67b644011","superPhihong":"528a82ee4b7956c31150a2e67b644011"}