فهرست منبع

auto update script executed

Toby Chui 1 سال پیش
والد
کامیت
181aa6fe88
5فایلهای تغییر یافته به همراه62 افزوده شده و 26 حذف شده
  1. 16 2
      mod/dynamicproxy/proxyRequestHandler.go
  2. 35 0
      routingrule.go
  3. 2 15
      start.go
  4. 9 8
      web/components/rproot.html
  5. 0 1
      web/components/status.html

+ 16 - 2
mod/dynamicproxy/proxyRequestHandler.go

@@ -7,6 +7,7 @@ import (
 	"net/http"
 	"net/url"
 	"path/filepath"
+	"sort"
 	"strings"
 
 	"imuslab.com/zoraxy/mod/dynamicproxy/dpcore"
@@ -37,6 +38,7 @@ func (router *Router) getProxyEndpointFromHostname(hostname string) *ProxyEndpoi
 	}
 
 	//No hit. Try with wildcard
+	matchProxyEndpoints := []*ProxyEndpoint{}
 	router.ProxyEndpoints.Range(func(k, v interface{}) bool {
 		ep := v.(*ProxyEndpoint)
 		match, err := filepath.Match(ep.RootOrMatchingDomain, hostname)
@@ -45,12 +47,24 @@ func (router *Router) getProxyEndpointFromHostname(hostname string) *ProxyEndpoi
 			return true
 		}
 		if match {
-			targetSubdomainEndpoint = ep
-			return false
+			//targetSubdomainEndpoint = ep
+			matchProxyEndpoints = append(matchProxyEndpoints, ep)
+			return true
 		}
 		return true
 	})
 
+	if len(matchProxyEndpoints) == 1 {
+		//Only 1 match
+		return matchProxyEndpoints[0]
+	} else if len(matchProxyEndpoints) > 1 {
+		//More than one match. Get the best match one
+		sort.Slice(matchProxyEndpoints, func(i, j int) bool {
+			return matchProxyEndpoints[i].RootOrMatchingDomain < matchProxyEndpoints[j].RootOrMatchingDomain
+		})
+		return matchProxyEndpoints[0]
+	}
+
 	return targetSubdomainEndpoint
 }
 

+ 35 - 0
routingrule.go

@@ -0,0 +1,35 @@
+package main
+
+import (
+	"net/http"
+	"strings"
+
+	"imuslab.com/zoraxy/mod/dynamicproxy"
+)
+
+/*
+  Routing Rule
+
+  This script handle special routing rules for some utilities functions
+*/
+
+// Register the system build-in routing rules into the core
+func registerBuildInRoutingRules() {
+	//Cloudflare email decoder
+	//It decode the email address if you are proxying a cloudflare protected site
+	//[email-protected] -> [email protected]
+	dynamicProxyRouter.AddRoutingRules(&dynamicproxy.RoutingRule{
+		ID: "cloudflare-decoder",
+		MatchRule: func(r *http.Request) bool {
+			return strings.HasSuffix(r.RequestURI, "cloudflare-static/email-decode.min.js")
+		},
+		RoutingHandler: func(w http.ResponseWriter, r *http.Request) {
+			decoder := "function fixObfuscatedEmails(){let t=document.getElementsByClassName(\"__cf_email__\");for(let e=0;e<t.length;e++){let r=t[e],l=r.getAttribute(\"data-cfemail\");if(l){let a=decrypt(l);r.setAttribute(\"href\",\"mailto:\"+a),r.innerHTML=a}}}function decrypt(t){let e=\"\",r=parseInt(t.substr(0,2),16);for(let l=2;l<t.length;l+=2){let a=parseInt(t.substr(l,2),16)^r;e+=String.fromCharCode(a)}try{e=decodeURIComponent(escape(e))}catch(f){console.error(f)}return e}fixObfuscatedEmails();"
+			w.Header().Set("Content-type", "text/javascript")
+			w.Write([]byte(decoder))
+		},
+		Enabled:                true,
+		UseSystemAccessControl: false,
+	})
+
+}

+ 2 - 15
start.go

@@ -11,7 +11,6 @@ import (
 	"imuslab.com/zoraxy/mod/acme"
 	"imuslab.com/zoraxy/mod/auth"
 	"imuslab.com/zoraxy/mod/database"
-	"imuslab.com/zoraxy/mod/dynamicproxy"
 	"imuslab.com/zoraxy/mod/dynamicproxy/redirection"
 	"imuslab.com/zoraxy/mod/ganserv"
 	"imuslab.com/zoraxy/mod/geodb"
@@ -240,18 +239,6 @@ func finalSequence() {
 	//Start ACME renew agent
 	acmeRegisterSpecialRoutingRule()
 
-	//TODO: REMOVE THIS AFTER TESTING
-	dynamicProxyRouter.AddRoutingRules(&dynamicproxy.RoutingRule{
-		ID: "cloudflare-decoder",
-		MatchRule: func(r *http.Request) bool {
-			return strings.HasSuffix(r.RequestURI, "cloudflare-static/email-decode.min.js")
-		},
-		RoutingHandler: func(w http.ResponseWriter, r *http.Request) {
-			decoder := "function fixObfuscatedEmails(){let t=document.getElementsByClassName(\"__cf_email__\");for(let e=0;e<t.length;e++){let r=t[e],l=r.getAttribute(\"data-cfemail\");if(l){let a=decrypt(l);r.setAttribute(\"href\",\"mailto:\"+a),r.innerHTML=a}}}function decrypt(t){let e=\"\",r=parseInt(t.substr(0,2),16);for(let l=2;l<t.length;l+=2){let a=parseInt(t.substr(l,2),16)^r;e+=String.fromCharCode(a)}try{e=decodeURIComponent(escape(e))}catch(f){console.error(f)}return e}fixObfuscatedEmails();"
-			w.Header().Set("Content-type", "text/javascript")
-			w.Write([]byte(decoder))
-		},
-		Enabled:                true,
-		UseSystemAccessControl: false,
-	})
+	//Inject routing rules
+	registerBuildInRoutingRules()
 }

+ 9 - 8
web/components/rproot.html

@@ -198,19 +198,20 @@
 
     //Set the new proxy root option
     function setProxyRoot(btn=undefined){
-        if (btn != undefined){
-            $(btn).addClass("disabled");
-        }
         var newpr = $("#proxyRoot").val();
-        if (newpr.trim() == ""){
-            $("#proxyRoot").parent().addClass('error');
-            return
-        }else{
-            $("#proxyRoot").parent().removeClass('error');
+        if (newpr.trim() == "" && currentDefaultSiteOption == 0){
+            //Fill in the web server info
+            newpr = "127.0.0.1:" +  $("#webserv_listenPort").val();
+            $("#proxyRoot").val(newpr);
+            
         }
 
         var rootReqTls = $("#rootReqTLS")[0].checked;
 
+        if (btn != undefined){
+            $(btn).addClass("disabled");
+        }
+
         //proxy mode or redirect mode, check for input values
         var defaultSiteValue = "";
         if (currentDefaultSiteOption == 1){

+ 0 - 1
web/components/status.html

@@ -96,7 +96,6 @@
                 Advance Settings
             </div>
             <div class="content">
-                <p>If you have no idea what are these, you can leave them as default :)</p>
                 <div id="tlsMinVer" class="ui toggle notloopbackOnly tlsEnabledOnly checkbox" style="margin-top: 0.6em;">
                     <input type="checkbox">
                     <label>Force TLS v1.2 or above<br>