Browse Source

auto update script executed

Toby Chui 1 year ago
parent
commit
d635d3c44e

+ 2 - 2
mod/dynamicproxy/proxyRequestHandler.go

@@ -75,7 +75,7 @@ func (h *ProxyHandler) subdomainRequest(w http.ResponseWriter, r *http.Request,
 			u, _ = url.Parse("wss://" + wsRedirectionEndpoint + requestURL)
 		}
 		h.logRequest(r, true, 101, "subdomain-websocket", target.Domain)
-		wspHandler := websocketproxy.NewProxy(u)
+		wspHandler := websocketproxy.NewProxy(u, target.SkipCertValidations)
 		wspHandler.ServeHTTP(w, r)
 		return
 	}
@@ -128,7 +128,7 @@ func (h *ProxyHandler) proxyRequest(w http.ResponseWriter, r *http.Request, targ
 			u, _ = url.Parse("wss://" + wsRedirectionEndpoint + r.URL.String())
 		}
 		h.logRequest(r, true, 101, "vdir-websocket", target.Domain)
-		wspHandler := websocketproxy.NewProxy(u)
+		wspHandler := websocketproxy.NewProxy(u, target.SkipCertValidations)
 		wspHandler.ServeHTTP(w, r)
 		return
 	}

+ 5 - 5
mod/sshprox/sshprox.go

@@ -29,9 +29,9 @@ import (
 */
 
 /*
-	Bianry embedding
+Bianry embedding
 
-	Make sure when compile, gotty binary exists in static.gotty
+Make sure when compile, gotty binary exists in static.gotty
 */
 var (
 	//go:embed gotty/*
@@ -61,7 +61,7 @@ func NewSSHProxyManager() *Manager {
 	}
 }
 
-//Get the next free port in the list
+// Get the next free port in the list
 func (m *Manager) GetNextPort() int {
 	nextPort := m.StartingPort
 	occupiedPort := make(map[int]bool)
@@ -96,7 +96,7 @@ func (m *Manager) HandleHttpByInstanceId(instanceId string, w http.ResponseWrite
 		r.Header.Set("A-Upgrade", "websocket")
 		requestURL = strings.TrimPrefix(requestURL, "/")
 		u, _ := url.Parse("ws://127.0.0.1:" + strconv.Itoa(targetInstance.AssignedPort) + "/" + requestURL)
-		wspHandler := websocketproxy.NewProxy(u)
+		wspHandler := websocketproxy.NewProxy(u, false)
 		wspHandler.ServeHTTP(w, r)
 		return
 	}
@@ -168,7 +168,7 @@ func (m *Manager) NewSSHProxy(binaryRoot string) (*Instance, error) {
 	return &thisInstance, nil
 }
 
-//Create a new Connection to target address
+// Create a new Connection to target address
 func (i *Instance) CreateNewConnection(listenPort int, username string, remoteIpAddr string, remotePort int) error {
 	//Create a gotty instance
 	connAddr := remoteIpAddr

+ 17 - 5
mod/websocketproxy/websocketproxy.go

@@ -2,6 +2,7 @@
 package websocketproxy
 
 import (
+	"crypto/tls"
 	"fmt"
 	"io"
 	"log"
@@ -46,16 +47,19 @@ type WebsocketProxy struct {
 	//  If nil, DefaultDialer is used.
 	Dialer *websocket.Dialer
 
-	Verbal bool
+	Verbal            bool
+	SkipTlsValidation bool
 }
 
 // ProxyHandler returns a new http.Handler interface that reverse proxies the
 // request to the given target.
-func ProxyHandler(target *url.URL) http.Handler { return NewProxy(target) }
+func ProxyHandler(target *url.URL, skipTlsValidation bool) http.Handler {
+	return NewProxy(target, skipTlsValidation)
+}
 
 // NewProxy returns a new Websocket reverse proxy that rewrites the
 // URL's to the scheme, host and base path provider in target.
-func NewProxy(target *url.URL) *WebsocketProxy {
+func NewProxy(target *url.URL, skipTlsValidation bool) *WebsocketProxy {
 	backend := func(r *http.Request) *url.URL {
 		// Shallow copy
 		u := *target
@@ -64,7 +68,7 @@ func NewProxy(target *url.URL) *WebsocketProxy {
 		u.RawQuery = r.URL.RawQuery
 		return &u
 	}
-	return &WebsocketProxy{Backend: backend, Verbal: false}
+	return &WebsocketProxy{Backend: backend, Verbal: false, SkipTlsValidation: skipTlsValidation}
 }
 
 // ServeHTTP implements the http.Handler that proxies WebSocket connections.
@@ -84,7 +88,15 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
 
 	dialer := w.Dialer
 	if w.Dialer == nil {
-		dialer = DefaultDialer
+		if w.SkipTlsValidation {
+			//Disable TLS secure check if target allow skip verification
+			bypassDialer := websocket.DefaultDialer
+			bypassDialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
+			dialer = bypassDialer
+		} else {
+			//Just use the default dialer come with gorilla websocket
+			dialer = DefaultDialer
+		}
 	}
 
 	// Pass headers from the incoming request to the dialer to forward them to

+ 2 - 2
mod/websocketproxy/websocketproxy_test.go

@@ -28,7 +28,7 @@ func TestProxy(t *testing.T) {
 	}
 
 	u, _ := url.Parse(backendURL)
-	proxy := NewProxy(u)
+	proxy := NewProxy(u, false)
 	proxy.Upgrader = upgrader
 
 	mux := http.NewServeMux()
@@ -46,7 +46,7 @@ func TestProxy(t *testing.T) {
 		mux2 := http.NewServeMux()
 		mux2.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 			// Don't upgrade if original host header isn't preserved
-			if r.Host !=  "127.0.0.1:7777" {
+			if r.Host != "127.0.0.1:7777" {
 				log.Printf("Host header set incorrectly.  Expecting 127.0.0.1:7777 got %s", r.Host)
 				return
 			}