浏览代码

Added shutdown password requirement on powering the host

TC pushbot 5 4 年之前
父节点
当前提交
2cbfc52ae4
共有 3 个文件被更改,包括 62 次插入17 次删除
  1. 2 8
      hardware.power.go
  2. 59 8
      web/SystemAO/boot/poweroff.html
  3. 1 1
      web/SystemAO/security/authreq.html

+ 2 - 8
hardware.power.go

@@ -45,7 +45,7 @@ func hardware_power_poweroff(w http.ResponseWriter, r *http.Request) {
 	}
 	}
 
 
 	//Double check password for this user
 	//Double check password for this user
-	password, err := mv(r, "pw", true)
+	password, err := mv(r, "password", true)
 	if err != nil {
 	if err != nil {
 		sendErrorResponse(w, "Password Incorrect")
 		sendErrorResponse(w, "Password Incorrect")
 		return
 		return
@@ -57,9 +57,6 @@ func hardware_power_poweroff(w http.ResponseWriter, r *http.Request) {
 		return
 		return
 	}
 	}
 
 
-	log.Println("Shutting Down")
-	return
-
 	if runtime.GOOS == "windows" {
 	if runtime.GOOS == "windows" {
 		//Only allow Linux to do power operation
 		//Only allow Linux to do power operation
 		cmd := exec.Command("shutdown", "-s", "-t", "20")
 		cmd := exec.Command("shutdown", "-s", "-t", "20")
@@ -115,7 +112,7 @@ func hardware_power_restart(w http.ResponseWriter, r *http.Request) {
 	}
 	}
 
 
 	//Double check password for this user
 	//Double check password for this user
-	password, err := mv(r, "pw", true)
+	password, err := mv(r, "password", true)
 	if err != nil {
 	if err != nil {
 		sendErrorResponse(w, "Password Incorrect")
 		sendErrorResponse(w, "Password Incorrect")
 		return
 		return
@@ -127,9 +124,6 @@ func hardware_power_restart(w http.ResponseWriter, r *http.Request) {
 		return
 		return
 	}
 	}
 
 
-	log.Println("Restarting")
-	return
-
 	if runtime.GOOS == "windows" {
 	if runtime.GOOS == "windows" {
 		//Only allow Linux to do power operation
 		//Only allow Linux to do power operation
 		cmd := exec.Command("shutdown", "-r", "-t", "20")
 		cmd := exec.Command("shutdown", "-r", "-t", "20")

+ 59 - 8
web/SystemAO/boot/poweroff.html

@@ -19,9 +19,9 @@
             <div class="ui divider"></div>
             <div class="ui divider"></div>
             <div class="ui segment">
             <div class="ui segment">
                 <h3 class="ui header">
                 <h3 class="ui header">
-                    <i class="green check circle icon"></i>
+                    <i id="sysConnStateIcon" class="green check circle icon"></i>
                     <div class="content">
                     <div class="content">
-                        System Online
+                        <span id="sysConnState">System Online</span>
                         <div class="sub header">Last update: <span id="lastupdateTime"></span></div>
                         <div class="sub header">Last update: <span id="lastupdateTime"></span></div>
                     </div>
                     </div>
                 </h3>
                 </h3>
@@ -31,16 +31,21 @@
             <p>Power Options</p>
             <p>Power Options</p>
             <button class="ui red button" onclick="shutdown();"><i class="power off icon"></i> Power Off</button>
             <button class="ui red button" onclick="shutdown();"><i class="power off icon"></i> Power Off</button>
             <button class="ui yellow button" onclick="restart();"><i class="refresh icon"></i> Restart</button>
             <button class="ui yellow button" onclick="restart();"><i class="refresh icon"></i> Restart</button>
+            <div id="msgbox" class="ui green message" style="display:none;">
+                <p><i class="checkmark icon"></i> <span id="succmsg"></span></p>
+            </div>
+            <div class="ui divider"></div>
             <div class="ui icon yellow message">
             <div class="ui icon yellow message">
                 <i class="yellow exclamation circle icon"></i>
                 <i class="yellow exclamation circle icon"></i>
                 <div class="content">
                 <div class="content">
                     <div class="header">
                     <div class="header">
                         Restart / Shutdown is risky
                         Restart / Shutdown is risky
                     </div>
                     </div>
-                    <p>Normally, Linux based server don't require reboot. If you decided to shutdown your host server, ArozOS will pass the shutdown sequence to the host operating system and there is no way to know from the web interface if the shutdown / restart process has completed. <br>
-                        <b>Please make sure you are shutting it down in a place where you can physcically power on the host again.</b></p>
+                    <p>If you decided to shutdown your host server, ArozOS will pass the shutdown sequence to the host operating system and there is no way to know from the web interface if the shutdown / restart process has completed. <br>
+                        <b>Please make sure you are shutting it down in a location where you can physcically power on the host again.</b></p>
                 </div>
                 </div>
             </div>
             </div>
+            
         </div>
         </div>
         <script>
         <script>
             $("#lastupdateTime").text(ao_module_utils.timeConverter(Date.now()/1000));
             $("#lastupdateTime").text(ao_module_utils.timeConverter(Date.now()/1000));
@@ -66,7 +71,7 @@
                     appicon: "SystemAO/security/img/lock.svg",
                     appicon: "SystemAO/security/img/lock.svg",
                     title: "Shutdown - Authentication Required",
                     title: "Shutdown - Authentication Required",
                     parent: ao_module_windowID,
                     parent: ao_module_windowID,
-                    callback: "handleCallback"
+                    callback: "handleShutdownCallback"
                 });
                 });
             }
             }
 
 
@@ -89,12 +94,58 @@
                     appicon: "SystemAO/security/img/lock.svg",
                     appicon: "SystemAO/security/img/lock.svg",
                     title: "Restart - Authentication Required",
                     title: "Restart - Authentication Required",
                     parent: ao_module_windowID,
                     parent: ao_module_windowID,
-                    callback: "handleCallback"
+                    callback: "handleRestartCallback"
                 });
                 });
             }
             }
 
 
-            function handleCallback(data){
-                console.log(data);
+            function handleRestartCallback(data){
+                if (data != false){
+                    //Not cancelled. Continue
+                    $("#msgbox").slideDown("fast").delay(5000).slideUp("fast");
+                    $("#succmsg").text("Host restarting...");
+                }
+            }
+
+            function handleShutdownCallback(data){
+                if (data != false){
+                    //Not cancelled. Continue
+                    $("#msgbox").slideDown("fast").delay(5000).slideUp("fast");
+                    $("#succmsg").text("Host will start shutdown sequence in 60 seconds");
+                }
+            }
+
+            handleConnectionStateCheck();
+            setTimeout(function(){
+                handleConnectionStateCheck();
+            }, 3000)
+
+            function handleConnectionStateCheck(){
+                if ($("#sysConnState").length > 0){
+                    $.ajax({
+                        url: "../../system/auth/checkLogin",
+                        data: {},
+                        success: function(){
+                            //Online
+                            $("#sysConnState").text("System Online");
+                            $("#lastupdateTime").text(ao_module_utils.timeConverter(Date.now()/1000));
+                            $("#sysConnStateIcon").attr("class","green check circle icon");
+
+                            setTimeout(function(){
+                                handleConnectionStateCheck();
+                            }, 3000)
+                        },
+                        error: function(){
+                            //Timeout
+                            $("#sysConnState").text("Disconnected");
+                            $("#lastupdateTime").text(ao_module_utils.timeConverter(Date.now()/1000));
+                            $("#sysConnStateIcon").attr("class","yellow exclamation circle icon");
+                            setTimeout(function(){
+                                handleConnectionStateCheck();
+                            }, 3000)
+                        },
+                        timeout: 1000
+                    });
+                }   
             }
             }
         </script>
         </script>
     </body>
     </body>

+ 1 - 1
web/SystemAO/security/authreq.html

@@ -81,7 +81,7 @@
             //Request endpoint
             //Request endpoint
             $.ajax({
             $.ajax({
                 url: "../../" + actionObject.api,
                 url: "../../" + actionObject.api,
-                data: data,
+                data: payload,
                 method: method,
                 method: method,
                 success: function(data){
                 success: function(data){
                     if (data.error != undefined){
                     if (data.error != undefined){