Browse Source

Fixed rate limit error on default site

Toby Chui 8 months ago
parent
commit
5ea17b50c9

+ 20 - 17
reverseproxy.go

@@ -225,7 +225,7 @@ func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	//Require basic auth?
+	// Require basic auth?
 	rba, _ := utils.PostPara(r, "bauth")
 	if rba == "" {
 		rba = "false"
@@ -234,23 +234,26 @@ func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
 	requireBasicAuth := (rba == "true")
 
 	// Require Rate Limiting?
-	rl, _ := utils.PostPara(r, "rate")
-	if rl == "" {
-		rl = "false"
-	}
-	requireRateLimit := (rl == "true")
-	rlnum, _ := utils.PostPara(r, "ratenum")
-	if rlnum == "" {
-		rlnum = "0"
-	}
-	proxyRateLimit, err := strconv.ParseInt(rlnum, 10, 64)
+	requireRateLimit := false
+	proxyRateLimit := 1000
+
+	requireRateLimit, err = utils.PostBool(r, "rate")
 	if err != nil {
-		utils.SendErrorResponse(w, "invalid rate limit number")
-		return
+		requireRateLimit = false
 	}
-	if proxyRateLimit <= 0 {
-		utils.SendErrorResponse(w, "rate limit number must be greater than 0")
-		return
+	if requireRateLimit {
+		proxyRateLimit, err = utils.PostInt(r, "ratenum")
+		if err != nil {
+			proxyRateLimit = 0
+		}
+		if err != nil {
+			utils.SendErrorResponse(w, "invalid rate limit number")
+			return
+		}
+		if proxyRateLimit <= 0 {
+			utils.SendErrorResponse(w, "rate limit number must be greater than 0")
+			return
+		}
 	}
 
 	// Bypass WebSocket Origin Check
@@ -335,7 +338,7 @@ func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
 			DefaultSiteValue:        "",
 			// Rate Limit
 			RequireRateLimit: requireRateLimit,
-			RateLimit:        proxyRateLimit,
+			RateLimit:        int64(proxyRateLimit),
 		}
 
 		preparedEndpoint, err := dynamicProxyRouter.PrepareProxyRoute(&thisProxyEndpoint)

File diff suppressed because it is too large
+ 88 - 27
www/templates/blacklist.html


File diff suppressed because it is too large
+ 32 - 21
www/templates/notfound.html


File diff suppressed because it is too large
+ 88 - 27
www/templates/whitelist.html


File diff suppressed because it is too large
+ 47 - 0
www/templates_uwu/blacklist.html


File diff suppressed because it is too large
+ 37 - 0
www/templates_uwu/notfound.html


File diff suppressed because it is too large
+ 47 - 0
www/templates_uwu/whitelist.html


Some files were not shown because too many files changed in this diff