mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-02-13 13:57:59 +00:00
Fix ipv6 hostname parsing for subscriptions (#3782)
This commit is contained in:
parent
b3555ce1b8
commit
fc6344b840
1 changed files with 24 additions and 1 deletions
|
|
@ -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://"
|
||||
|
|
|
|||
Loading…
Reference in a new issue