Browse Source

auto update script executed

tobychui 1 year ago
parent
commit
1f72c279cd
2 changed files with 41 additions and 23 deletions
  1. 16 10
      mod/dynamicproxy/dynamicproxy.go
  2. 25 13
      web/components/rproot.html

+ 16 - 10
mod/dynamicproxy/dynamicproxy.go

@@ -95,15 +95,21 @@ func (router *Router) StartProxyService() error {
 	}
 
 	if router.Option.UseTls {
-		//Serve with TLS mode
-		ln, err := tls.Listen("tcp", ":"+strconv.Itoa(router.Option.Port), config)
-		if err != nil {
-			log.Println(err)
-			router.Running = false
-			return err
+		/*
+			//Serve with TLS mode
+			ln, err := tls.Listen("tcp", ":"+strconv.Itoa(router.Option.Port), config)
+			if err != nil {
+				log.Println(err)
+				router.Running = false
+				return err
+			}
+			router.tlsListener = ln
+		*/
+		router.server = &http.Server{
+			Addr:      ":" + strconv.Itoa(router.Option.Port),
+			Handler:   router.mux,
+			TLSConfig: config,
 		}
-		router.tlsListener = ln
-		router.server = &http.Server{Addr: ":" + strconv.Itoa(router.Option.Port), Handler: router.mux}
 		router.Running = true
 
 		if router.Option.Port != 80 && router.Option.ForceHttpsRedirect {
@@ -140,7 +146,7 @@ func (router *Router) StartProxyService() error {
 
 			//Start the http server that listens to port 80 and redirect to 443
 			go func() {
-				if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
+				if err := httpServer.ListenAndServeTLS("", ""); err != nil && err != http.ErrServerClosed {
 					//Unable to startup port 80 listener. Handle shutdown process gracefully
 					stopChan <- true
 					log.Fatalf("Could not start server: %v\n", err)
@@ -152,7 +158,7 @@ func (router *Router) StartProxyService() error {
 		//Start the TLS server
 		log.Println("Reverse proxy service started in the background (TLS mode)")
 		go func() {
-			if err := router.server.Serve(ln); err != nil && err != http.ErrServerClosed {
+			if err := router.server.ListenAndServeTLS("", ""); err != nil && err != http.ErrServerClosed {
 				log.Fatalf("Could not start server: %v\n", err)
 			}
 		}()

+ 25 - 13
web/components/rproot.html

@@ -107,18 +107,26 @@
         updateWebServerLinkSettings();
     });
 
-
+    //Update the current web server port settings
     function updateWebServerLinkSettings(){
-        let currentProxyRoot = $("#proxyRoot").val().trim();
-        $.get("/api/webserv/status", function(webservStatus){
-            if (currentProxyRoot == "127.0.0.1:" + webservStatus.ListeningPort || currentProxyRoot == "localhost:" + webservStatus.ListeningPort){
-                //The root is pointing to the static web server
-                $("#useStaticWebServer").parent().checkbox("set checked");
+        isUsingStaticWebServerAsRoot(function(isUsingWebServ){
+            if (isUsingWebServ){
                 $(".webservRootDisabled").addClass("disabled");
             }else{
                 $(".webservRootDisabled").removeClass("disabled");
             }
+        })
+    }
+
+    function isUsingStaticWebServerAsRoot(callback){
+        let currentProxyRoot = $("#proxyRoot").val().trim();
+        $.get("/api/webserv/status", function(webservStatus){
+            if (currentProxyRoot == "127.0.0.1:" + webservStatus.ListeningPort || currentProxyRoot == "localhost:" + webservStatus.ListeningPort){
+                return callback(true);
+            }
+            return callback(false);
         });
+        
     }
     
     function updateRootSettingStates(){
@@ -130,6 +138,7 @@
             }
         });
     }
+
     //Bind event to tab switch
     tabSwitchEventBind["setroot"] = function(){
         //On switch over to this page, update root info
@@ -161,6 +170,7 @@
     }
     checkCustomRedirectForUnsetSubd();
 
+    //Check if the given domain will redirect to https
     function checkRootRequireTLS(targetDomain){
         //Trim off the http or https from the origin
         if (targetDomain.startsWith("http://")){
@@ -187,7 +197,7 @@
        })
     }
 
-
+    //Set the new proxy root option
     function setProxyRoot(){
         var newpr = $("#proxyRoot").val();
         if (newpr.trim() == ""){
@@ -210,18 +220,20 @@
                     //OK
                     initRootInfo(function(){
                         //Check if WebServ is enabled
-                        let currentProxyRoot = $("#proxyRoot").val().trim();
-                        $.get("/api/webserv/status", function(webservStatus){
-                            if (!webservStatus.Running){
+                        isUsingStaticWebServerAsRoot(function(isUsingWebServ){
+                            if (isUsingWebServ){
                                 //Force enable static web server
-                                $("#webserv_enable").parent().checkbox("set checked");
+                                //See webserv.html for details
+                                setWebServerRunningState(true);
                             }
-
+                            
                             setTimeout(function(){
+                                 //Update the checkbox
                                 updateWebServerLinkSettings();
                                 msgbox("Proxy Root Updated");
                             }, 1000);
-                        });
+                            
+                        })
                     });
                     
                 }