From 156fa5dacecd9ce492df76c8f8b82e6078519f98 Mon Sep 17 00:00:00 2001 From: tobychui Date: Fri, 20 Oct 2023 11:01:28 +0800 Subject: [PATCH] Bug fix + Added potential fix for #67 + Update version number + Changed default static web port to 5487 so it is even more unlikely to be used + --- src/main.go | 4 +-- src/start.go | 2 +- src/web/components/rproot.html | 63 ++++++++++++++++++++++++++++----- src/web/components/webserv.html | 4 +-- 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/src/main.go b/src/main.go index 4177a75..45d5ec5 100644 --- a/src/main.go +++ b/src/main.go @@ -47,9 +47,9 @@ var allowWebFileManager = flag.Bool("webfm", true, "Enable web file manager for var ( name = "Zoraxy" - version = "2.6.7" + version = "2.6.8" nodeUUID = "generic" - development = false //Set this to false to use embedded web fs + development = true //Set this to false to use embedded web fs bootTime = time.Now().Unix() /* diff --git a/src/start.go b/src/start.go index 4dd4aa8..6d210cb 100644 --- a/src/start.go +++ b/src/start.go @@ -220,7 +220,7 @@ func startupSequence() { staticWebServer = webserv.NewWebServer(&webserv.WebServerOptions{ Sysdb: sysdb, - Port: "8081", //Default Port + Port: "5487", //Default Port WebRoot: *staticWebServerRoot, EnableDirectoryListing: true, EnableWebDirManager: *allowWebFileManager, diff --git a/src/web/components/rproot.html b/src/web/components/rproot.html index 6e0bfc7..57ababf 100644 --- a/src/web/components/rproot.html +++ b/src/web/components/rproot.html @@ -75,13 +75,13 @@ $("#rootReqTLS").parent().addClass("disabled"); //Check if web server is enabled. If not, ask if the user want to enable it - if (!$("#webserv_enable").parent().checkbox("is checked")){ + /*if (!$("#webserv_enable").parent().checkbox("is checked")){ confirmBox("Enable static web server now?", function(choice){ if (choice == true){ $("#webserv_enable").parent().checkbox("set checked"); } }); - } + }*/ }else{ $("#rootReqTLS").parent().removeClass("disabled"); $("#proxyRoot").parent().removeClass("disabled"); @@ -89,7 +89,7 @@ } } - function initRootInfo(){ + function initRootInfo(callback=undefined){ $.get("/api/proxy/list?type=root", function(data){ if (data == null){ @@ -97,11 +97,38 @@ $("#proxyRoot").val(data.Domain); checkRootRequireTLS(data.Domain); } + + if (callback != undefined){ + callback(); + } + }); + } + initRootInfo(function(){ + updateWebServerLinkSettings(); + }); + + //Update the current web server port settings + function updateWebServerLinkSettings(){ + 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); }); } - initRootInfo(); - + function updateRootSettingStates(){ $.get("/api/cert/tls", function(data){ if (data == true){ @@ -111,6 +138,7 @@ } }); } + //Bind event to tab switch tabSwitchEventBind["setroot"] = function(){ //On switch over to this page, update root info @@ -137,11 +165,12 @@ let useRedirect = $("#unsetRedirect")[0].checked; updateRedirectionDomainSettingInputBox(useRedirect); }); - }) + }); } 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://")){ @@ -168,7 +197,7 @@ }) } - + //Set the new proxy root option function setProxyRoot(){ var newpr = $("#proxyRoot").val(); if (newpr.trim() == ""){ @@ -189,8 +218,24 @@ msgbox(data.error, false, 5000); }else{ //OK - initRootInfo(); - msgbox("Proxy Root Updated") + initRootInfo(function(){ + //Check if WebServ is enabled + isUsingStaticWebServerAsRoot(function(isUsingWebServ){ + if (isUsingWebServ){ + //Force enable static web server + //See webserv.html for details + setWebServerRunningState(true); + } + + setTimeout(function(){ + //Update the checkbox + updateWebServerLinkSettings(); + msgbox("Proxy Root Updated"); + }, 1000); + + }) + }); + } } }); diff --git a/src/web/components/webserv.html b/src/web/components/webserv.html index a0e201f..6f94822 100644 --- a/src/web/components/webserv.html +++ b/src/web/components/webserv.html @@ -17,7 +17,7 @@

Web Server Settings

-
+
@@ -37,7 +37,7 @@ See the -webserv flag for more details.
-
+
Use http://127.0.0.1:8081 in proxy rules to access the web server