Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbakatrouble <bakatrouble@gmail.com>2026-02-11 17:33:53 +0300
committerGitHub <noreply@github.com>2026-02-11 17:33:53 +0300
commitfc6344b840d9153dbf43eb58b08523ca15350b25 (patch)
tree6a86ee1c9ebe817e701114b7bb8bae0145bb9213 /web/service
parentb3555ce1b889d17fb0bb486315871a8f62f1e333 (diff)
Fix ipv6 hostname parsing for subscriptions (#3782)
Diffstat (limited to 'web/service')
-rw-r--r--web/service/setting.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/web/service/setting.go b/web/service/setting.go
index 495dc522..1e95c2df 100644
--- a/web/service/setting.go
+++ b/web/service/setting.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "net"
"reflect"
"strconv"
"strings"
@@ -717,6 +718,28 @@ func (s *SettingService) GetDefaultXrayConfig() (any, error) {
return jsonData, nil
}
+func extractHostname(host string) string {
+ h, _, err := net.SplitHostPort(host)
+ // Err is not nil means host does not contain port
+ if err != nil {
+ h = host
+ }
+
+ ip := net.ParseIP(h)
+ // If it's not an IP, return as is
+ if ip == nil {
+ return h
+ }
+
+ // If it's an IPv4, return as is
+ if ip.To4() != nil {
+ return h
+ }
+
+ // IPv6 needs bracketing
+ return "[" + h + "]"
+}
+
func (s *SettingService) GetDefaultSettings(host string) (any, error) {
type settingFunc func() (any, error)
settings := map[string]settingFunc{
@@ -767,7 +790,7 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) {
subTLS = true
}
if subDomain == "" {
- subDomain = strings.Split(host, ":")[0]
+ subDomain = extractHostname(host)
}
if subTLS {
subURI = "https://"