瀏覽代碼

auto update script executed

Toby Chui 1 年之前
父節點
當前提交
303ff9dd77
共有 5 個文件被更改,包括 45 次插入5 次删除
  1. 1 1
      main.go
  2. 6 0
      mod/dynamicproxy/dpcore/dpcore.go
  3. 19 1
      mod/uptime/uptime.go
  4. 18 3
      web/components/uptime.html
  5. 1 0
      wrappers.go

+ 1 - 1
main.go

@@ -40,7 +40,7 @@ var (
 	name        = "Zoraxy"
 	version     = "2.6.3"
 	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()
 
 	/*

+ 6 - 0
mod/dynamicproxy/dpcore/dpcore.go

@@ -278,6 +278,12 @@ func addXForwardedForHeader(req *http.Request) {
 			clientIP = strings.Join(prior, ", ") + ", " + clientIP
 		}
 		req.Header.Set("X-Forwarded-For", clientIP)
+		if req.TLS != nil {
+			req.Header.Set("X-Forwarded-Proto", "https")
+		} else {
+			req.Header.Set("X-Forwarded-Proto", "http")
+		}
+
 	}
 }
 

+ 19 - 1
mod/uptime/uptime.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"log"
 	"net/http"
+	"strings"
 	"time"
 
 	"imuslab.com/zoraxy/mod/utils"
@@ -220,7 +221,24 @@ func getWebsiteStatusWithLatency(url string) (bool, int64, int) {
 func getWebsiteStatus(url string) (int, error) {
 	resp, err := http.Get(url)
 	if err != nil {
-		return 0, err
+		//Try replace the http with https and vise versa
+		rewriteURL := ""
+		if strings.Contains(url, "https://") {
+			rewriteURL = strings.ReplaceAll(url, "https://", "http://")
+		} else if strings.Contains(url, "http://") {
+			rewriteURL = strings.ReplaceAll(url, "http://", "https://")
+		}
+
+		resp, err = http.Get(rewriteURL)
+		if err != nil {
+			if strings.Contains(err.Error(), "http: server gave HTTP response to HTTPS client") {
+				//Invalid downstream reverse proxy settings, but it is online
+				//return SSL handshake failed
+				return 525, nil
+			}
+			return 0, err
+		}
+
 	}
 	status_code := resp.StatusCode
 	resp.Body.Close()

+ 18 - 3
web/components/uptime.html

@@ -109,7 +109,13 @@
                 }
                 ontimeRate++;
             }else{
-                dotType = "offline";
+                if (thisStatus.StatusCode >= 500 && thisStatus.StatusCode < 600){
+                    //Special type of error, cause by downstream reverse proxy
+                    dotType = "error";
+                }else{
+                    dotType = "offline";
+                }
+                
             }
 
             let datetime = format_time(thisStatus.Timestamp);
@@ -126,12 +132,20 @@
         //Check of online status now
         let currentOnlineStatus = "Unknown";
         let onlineStatusCss = ``;
+        let reminderEle = ``;
         if (value[value.length - 1].Online){
             currentOnlineStatus = `<i class="circle icon"></i> Online`;
             onlineStatusCss = `color: #3bd671;`;
         }else{
-            currentOnlineStatus = `<i class="circle icon"></i> Offline`;
-            onlineStatusCss = `color: #df484a;`;
+            if (value[value.length - 1].StatusCode >= 500 && value[value.length - 1].StatusCode < 600){
+                currentOnlineStatus = `<i class="exclamation circle icon"></i> Misconfigured`;
+                onlineStatusCss = `color: #f38020;`;
+                reminderEle = `<small style="${onlineStatusCss}">Downstream proxy server is online with misconfigured settings</small>`;
+            }else{
+                currentOnlineStatus = `<i class="circle icon"></i> Offline`;
+                onlineStatusCss = `color: #df484a;`;
+            }
+           
         }
 
         //Generate the html
@@ -151,6 +165,7 @@
             <div class="status" style="marign-top: 1em;">
                 ${statusDotList}
             </div>
+            ${reminderEle}
             <div class="ui divider"></div>
         </div>`);
     }

+ 1 - 0
wrappers.go

@@ -117,6 +117,7 @@ func GetUptimeTargetsFromReverseProxyRules(dp *dynamicproxy.Router) []*uptime.Ta
 			url = "https://" + target.Domain
 			protocol = "https"
 		}
+
 		UptimeTargets = append(UptimeTargets, &uptime.Target{
 			ID:       subd,
 			Name:     subd,