From f92ff068f38255150e9a214438029ba51545eed9 Mon Sep 17 00:00:00 2001 From: Jemmy Date: Wed, 2 Jul 2025 17:53:33 +0800 Subject: [PATCH] Added Proxy Protocol V1 to Stream Proxy UI - Added a checkbox for Proxy Protocol V1. - Modified related Config setting function. --- src/mod/streamproxy/handler.go | 6 +++--- src/mod/streamproxy/streamproxy.go | 5 +++-- src/mod/streamproxy/tcpprox.go | 2 +- src/web/components/streamprox.html | 21 +++++++++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/mod/streamproxy/handler.go b/src/mod/streamproxy/handler.go index 1d2aaf9..22d523a 100644 --- a/src/mod/streamproxy/handler.go +++ b/src/mod/streamproxy/handler.go @@ -47,8 +47,7 @@ func (m *Manager) HandleAddProxyConfig(w http.ResponseWriter, r *http.Request) { useTCP, _ := utils.PostBool(r, "useTCP") useUDP, _ := utils.PostBool(r, "useUDP") - // useProxyProtocol, _ := utils.PostBool(r, "useProxyProtocol") - useProxyProtocol := true + useProxyProtocol, _ := utils.PostBool(r, "useProxyProtocol") //Create the target config newConfigUUID := m.NewConfig(&ProxyRelayOptions{ @@ -78,6 +77,7 @@ func (m *Manager) HandleEditProxyConfigs(w http.ResponseWriter, r *http.Request) proxyAddr, _ := utils.PostPara(r, "proxyAddr") useTCP, _ := utils.PostBool(r, "useTCP") useUDP, _ := utils.PostBool(r, "useUDP") + useProxyProtocol, _ := utils.PostBool(r, "useProxyProtocol") newTimeoutStr, _ := utils.PostPara(r, "timeout") newTimeout := -1 @@ -90,7 +90,7 @@ func (m *Manager) HandleEditProxyConfigs(w http.ResponseWriter, r *http.Request) } // Call the EditConfig method to modify the configuration - err = m.EditConfig(configUUID, newName, listenAddr, proxyAddr, useTCP, useUDP, newTimeout) + err = m.EditConfig(configUUID, newName, listenAddr, proxyAddr, useTCP, useUDP, useProxyProtocol, newTimeout) if err != nil { utils.SendErrorResponse(w, err.Error()) return diff --git a/src/mod/streamproxy/streamproxy.go b/src/mod/streamproxy/streamproxy.go index e3f8057..4e3cc90 100644 --- a/src/mod/streamproxy/streamproxy.go +++ b/src/mod/streamproxy/streamproxy.go @@ -42,7 +42,7 @@ type ProxyRelayConfig struct { ProxyTargetAddr string //Proxy target address UseTCP bool //Enable TCP proxy UseUDP bool //Enable UDP proxy - UseProxyProtocol bool //Enable Proxy Protocol + UseProxyProtocol bool //Enable Proxy Protocol Timeout int //Timeout for connection in sec tcpStopChan chan bool //Stop channel for TCP listener udpStopChan chan bool //Stop channel for UDP listener @@ -184,7 +184,7 @@ func (m *Manager) GetConfigByUUID(configUUID string) (*ProxyRelayConfig, error) } // Edit the config based on config UUID, leave empty for unchange fields -func (m *Manager) EditConfig(configUUID string, newName string, newListeningAddr string, newProxyAddr string, useTCP bool, useUDP bool, newTimeout int) error { +func (m *Manager) EditConfig(configUUID string, newName string, newListeningAddr string, newProxyAddr string, useTCP bool, useUDP bool, useProxyProtocol bool, newTimeout int) error { // Find the config with the specified UUID foundConfig, err := m.GetConfigByUUID(configUUID) if err != nil { @@ -204,6 +204,7 @@ func (m *Manager) EditConfig(configUUID string, newName string, newListeningAddr foundConfig.UseTCP = useTCP foundConfig.UseUDP = useUDP + foundConfig.UseProxyProtocol = useProxyProtocol if newTimeout != -1 { if newTimeout < 0 { diff --git a/src/mod/streamproxy/tcpprox.go b/src/mod/streamproxy/tcpprox.go index 439a8ee..f817edf 100644 --- a/src/mod/streamproxy/tcpprox.go +++ b/src/mod/streamproxy/tcpprox.go @@ -145,7 +145,7 @@ func (c *ProxyRelayConfig) Port2host(allowPort string, targetAddress string, sto //Connection error. Retry continue } - log.Println("[+]", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + go func(targetAddress string) { log.Println("[+]", "start connect host:["+targetAddress+"]") target, err := net.Dial("tcp", targetAddress) diff --git a/src/web/components/streamprox.html b/src/web/components/streamprox.html index d30ddbd..f1593d5 100644 --- a/src/web/components/streamprox.html +++ b/src/web/components/streamprox.html @@ -73,6 +73,14 @@ Forward UDP request on this listening socket +
+
+ + +
+
@@ -195,6 +203,10 @@ modeText.push("UDP") } + if (config.UseProxyProtocol){ + modeText.push("ProxyProtocol V1") + } + modeText = modeText.join(" & ") var thisConfig = encodeURIComponent(JSON.stringify(config)); @@ -252,6 +264,14 @@ $(checkboxEle).checkbox("set unchecked"); } return; + }else if (key == "UseProxyProtocol"){ + let checkboxEle = $("#streamProxyForm input[name=useProxyProtocol]").parent(); + if (value === true){ + $(checkboxEle).checkbox("set checked"); + }else{ + $(checkboxEle).checkbox("set unchecked"); + } + return; }else if (key == "ListeningAddress"){ field = $("#streamProxyForm input[name=listenAddr]"); }else if (key == "ProxyTargetAddr"){ @@ -301,6 +321,7 @@ proxyAddr: $("#streamProxyForm input[name=proxyAddr]").val().trim(), useTCP: $("#streamProxyForm input[name=useTCP]")[0].checked , useUDP: $("#streamProxyForm input[name=useUDP]")[0].checked , + useProxyProtocol: $("#streamProxyForm input[name=useProxyProtocol]")[0].checked , timeout: parseInt($("#streamProxyForm input[name=timeout]").val().trim()), }, success: function(response) {