Преглед изворни кода

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
-	password, err := mv(r, "pw", true)
+	password, err := mv(r, "password", true)
 	if err != nil {
 		sendErrorResponse(w, "Password Incorrect")
 		return
@@ -57,9 +57,6 @@ func hardware_power_poweroff(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	log.Println("Shutting Down")
-	return
-
 	if runtime.GOOS == "windows" {
 		//Only allow Linux to do power operation
 		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
-	password, err := mv(r, "pw", true)
+	password, err := mv(r, "password", true)
 	if err != nil {
 		sendErrorResponse(w, "Password Incorrect")
 		return
@@ -127,9 +124,6 @@ func hardware_power_restart(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	log.Println("Restarting")
-	return
-
 	if runtime.GOOS == "windows" {
 		//Only allow Linux to do power operation
 		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 segment">
                 <h3 class="ui header">
-                    <i class="green check circle icon"></i>
+                    <i id="sysConnStateIcon" class="green check circle icon"></i>
                     <div class="content">
-                        System Online
+                        <span id="sysConnState">System Online</span>
                         <div class="sub header">Last update: <span id="lastupdateTime"></span></div>
                     </div>
                 </h3>
@@ -31,16 +31,21 @@
             <p>Power Options</p>
             <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>
+            <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">
                 <i class="yellow exclamation circle icon"></i>
                 <div class="content">
                     <div class="header">
                         Restart / Shutdown is risky
                     </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>
         <script>
             $("#lastupdateTime").text(ao_module_utils.timeConverter(Date.now()/1000));
@@ -66,7 +71,7 @@
                     appicon: "SystemAO/security/img/lock.svg",
                     title: "Shutdown - Authentication Required",
                     parent: ao_module_windowID,
-                    callback: "handleCallback"
+                    callback: "handleShutdownCallback"
                 });
             }
 
@@ -89,12 +94,58 @@
                     appicon: "SystemAO/security/img/lock.svg",
                     title: "Restart - Authentication Required",
                     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>
     </body>

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

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