Browse Source

fix: update extclient ingress endpoint/port with host changes

the_aceix 2 tháng trước cách đây
mục cha
commit
91c5fe0cf3
3 tập tin đã thay đổi với 18 bổ sung0 xóa
  1. 1 0
      controllers/hosts.go
  2. 6 0
      pro/controllers/users.go
  3. 11 0
      utils/utils.go

+ 1 - 0
controllers/hosts.go

@@ -308,6 +308,7 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
 			}
 		}
 	}()
+
 	logic.LogEvent(&models.Event{
 		Action: models.Update,
 		Source: models.Subject{

+ 6 - 0
pro/controllers/users.go

@@ -1304,6 +1304,12 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
 			if extClient.DNS == "" {
 				extClient.DNS = node.IngressDNS
 			}
+
+			extClient.IngressGatewayEndpoint = utils.GetExtClientEndpoint(
+				host.EndpointIP,
+				host.EndpointIPv6,
+				logic.GetPeerListenPort(host),
+			)
 			extClient.AllowedIPs = logic.GetExtclientAllowedIPs(extClient)
 			gws = append(gws, models.UserRemoteGws{
 				GwID:              node.ID.String(),

+ 11 - 0
utils/utils.go

@@ -1,7 +1,9 @@
 package utils
 
 import (
+	"fmt"
 	"log/slog"
+	"net"
 	"runtime"
 	"strings"
 	"time"
@@ -75,3 +77,12 @@ func NoEmptyStringToCsv(strs ...string) string {
 	}
 	return sb.String()
 }
+
+// GetExtClientEndpoint returns the external client endpoint in the format "host:port" or "[host]:port" for IPv6
+func GetExtClientEndpoint(hostIpv4Endpoint, hostIpv6Endpoint net.IP, hostListenPort int) string {
+	if hostIpv4Endpoint.To4() == nil {
+		return fmt.Sprintf("[%s]:%d", hostIpv6Endpoint.String(), hostListenPort)
+	} else {
+		return fmt.Sprintf("%s:%d", hostIpv4Endpoint.String(), hostListenPort)
+	}
+}