Browse Source

auto update script executed

Toby Chui 2 years ago
parent
commit
aa19c7d4e0
3 changed files with 19 additions and 10 deletions
  1. 5 5
      main.go
  2. 13 4
      mod/dynamicproxy/dynamicproxy.go
  3. 1 1
      web/components/status.html

+ 5 - 5
main.go

@@ -20,7 +20,7 @@ import (
 	"imuslab.com/zoraxy/mod/uptime"
 )
 
-//General flags
+// General flags
 var noauth = flag.Bool("noauth", false, "Disable authentication for management interface")
 var showver = flag.Bool("version", false, "Show version of this server")
 
@@ -60,11 +60,11 @@ func main() {
 		Name:        name,
 		Desc:        "Dynamic Reverse Proxy Server",
 		Group:       "Network",
-		IconPath:    "reverseproxy/img/small_icon.png",
+		IconPath:    "zoraxy/img/small_icon.png",
 		Version:     version,
-		StartDir:    "reverseproxy/index.html",
+		StartDir:    "zoraxy/index.html",
 		SupportFW:   true,
-		LaunchFWDir: "reverseproxy/index.html",
+		LaunchFWDir: "zoraxy/index.html",
 		SupportEmb:  false,
 		InitFWSize:  []int{1080, 580},
 	})
@@ -135,7 +135,7 @@ func main() {
 
 	time.Sleep(500 * time.Millisecond)
 	//Any log println will be shown in the core system via STDOUT redirection. But not STDIN.
-	log.Println("ReverseProxy started. Visit control panel at http://localhost" + handler.Port)
+	log.Println("Zoraxy started. Visit control panel at http://localhost" + handler.Port)
 	err = http.ListenAndServe(handler.Port, nil)
 
 	if err != nil {

+ 13 - 4
mod/dynamicproxy/dynamicproxy.go

@@ -22,7 +22,7 @@ import (
 )
 
 /*
-	Zoraxy Dynamic Proxy
+Zoraxy Dynamic Proxy
 */
 type RouterOption struct {
 	Port               int
@@ -122,12 +122,21 @@ func (router *Router) StartProxyService() error {
 		router.server = &http.Server{Addr: ":" + strconv.Itoa(router.Option.Port), Handler: router.mux}
 		router.Running = true
 
-		if router.Option.Port == 443 && router.Option.ForceHttpsRedirect {
+		if router.Option.Port != 80 && router.Option.ForceHttpsRedirect {
 			//Add a 80 to 443 redirector
 			httpServer := &http.Server{
 				Addr: ":80",
 				Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-					http.Redirect(w, r, "https://"+r.Host+r.RequestURI, http.StatusTemporaryRedirect)
+					protocol := "http://"
+					if router.Option.UseTls {
+						protocol = "https://"
+					}
+					if router.Option.Port == 443 && router.Option.UseTls {
+						http.Redirect(w, r, protocol+r.Host+r.RequestURI, http.StatusTemporaryRedirect)
+					} else {
+						http.Redirect(w, r, protocol+r.Host+":"+strconv.Itoa(router.Option.Port)+r.RequestURI, http.StatusTemporaryRedirect)
+					}
+
 				}),
 				ReadTimeout:  3 * time.Second,
 				WriteTimeout: 3 * time.Second,
@@ -311,7 +320,7 @@ func (router *Router) SetRootProxy(proxyLocation string, requireTLS bool) error
 	return nil
 }
 
-//Helpers to export the syncmap for easier processing
+// Helpers to export the syncmap for easier processing
 func (r *Router) GetSDProxyEndpointsAsMap() map[string]*SubdomainEndpoint {
 	m := make(map[string]*SubdomainEndpoint)
 	r.SubdomainEndpoint.Range(func(key, value interface{}) bool {

+ 1 - 1
web/components/status.html

@@ -67,7 +67,7 @@
 <div id="redirect" class="ui toggle checkbox" style="margin-top: 0.6em;">
     <input type="checkbox">
     <label>Force redirect HTTP request to HTTPS<br>
-        <small>(Only apply when listening port is 443)</small></label>
+        <small>(Only apply when listening port is not 80)</small></label>
 </div>
 <br>
 <div id="portUpdateSucc" class="ui green message" style="display:none;">