mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-16 15:17:14 +00:00
refactor(panel): drop two duplicated helpers
SettingService.GetDefaultJSONConfig was a byte-identical copy of GetDefaultXrayConfig with no callers anywhere in the tree. amneziawgnet.normalizeDNSServer re-implemented the exported amneziawg.NormalizeDNSServer line for line, in a file that already imports that package for EffectiveMTU three lines above it. Its two callers now use the exported one, so the bare-IP-to-host:port rule has a single definition.
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
"gvisor.dev/gvisor/pkg/tcpip"
|
"gvisor.dev/gvisor/pkg/tcpip"
|
||||||
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
||||||
|
|
||||||
|
"github.com/mhsanaei/3x-ui/v3/internal/amneziawg"
|
||||||
"github.com/mhsanaei/3x-ui/v3/internal/logger"
|
"github.com/mhsanaei/3x-ui/v3/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -78,7 +79,7 @@ func dnsCacheKey(tag, dnsServer, host string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resolveTunnelVia(ctx context.Context, dev *Device, tag string, dnsServer string, host string) (netip.Addr, error) {
|
func resolveTunnelVia(ctx context.Context, dev *Device, tag string, dnsServer string, host string) (netip.Addr, error) {
|
||||||
normDNS := normalizeDNSServer(dnsServer)
|
normDNS := amneziawg.NormalizeDNSServer(dnsServer)
|
||||||
if normDNS == "" {
|
if normDNS == "" {
|
||||||
normDNS = defaultDNSFor(dev.LocalAddresses())
|
normDNS = defaultDNSFor(dev.LocalAddresses())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"gvisor.dev/gvisor/pkg/tcpip"
|
"gvisor.dev/gvisor/pkg/tcpip"
|
||||||
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
||||||
|
|
||||||
|
"github.com/mhsanaei/3x-ui/v3/internal/amneziawg"
|
||||||
"github.com/mhsanaei/3x-ui/v3/internal/logger"
|
"github.com/mhsanaei/3x-ui/v3/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -77,7 +78,7 @@ func (s *socks5EgressServer) SetDNSServer(addr string) {
|
|||||||
func (s *socks5EgressServer) SetStack(tag string, dev *Device, dnsServer ...string) {
|
func (s *socks5EgressServer) SetStack(tag string, dev *Device, dnsServer ...string) {
|
||||||
norm := ""
|
norm := ""
|
||||||
if len(dnsServer) > 0 && dnsServer[0] != "" {
|
if len(dnsServer) > 0 && dnsServer[0] != "" {
|
||||||
norm = normalizeDNSServer(dnsServer[0])
|
norm = amneziawg.NormalizeDNSServer(dnsServer[0])
|
||||||
}
|
}
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
prevDev := s.stacks[tag]
|
prevDev := s.stacks[tag]
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package amneziawgnet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -53,21 +52,6 @@ func outboundFingerprint(inst amneziawg.OutboundInstance) string {
|
|||||||
strings.Join(inst.Address, ","))
|
strings.Join(inst.Address, ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalizeDNSServer normalizes a configured DNS server to host:port.
|
|
||||||
func normalizeDNSServer(s string) string {
|
|
||||||
s = strings.TrimSpace(s)
|
|
||||||
if s == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if addr, err := netip.ParseAddr(s); err == nil {
|
|
||||||
return netip.AddrPortFrom(addr, 53).String()
|
|
||||||
}
|
|
||||||
if ap, err := netip.ParseAddrPort(s); err == nil {
|
|
||||||
return ap.String()
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reconcile converges devices to desired and stops removed tags; per-tick
|
// Reconcile converges devices to desired and stops removed tags; per-tick
|
||||||
// contract of Manager.Reconcile -- errors log, never abort the batch.
|
// contract of Manager.Reconcile -- errors log, never abort the batch.
|
||||||
func (m *OutboundManager) Reconcile(desired []OutboundDesired) {
|
func (m *OutboundManager) Reconcile(desired []OutboundDesired) {
|
||||||
|
|||||||
@@ -209,15 +209,6 @@ var defaultValueMap = map[string]string{
|
|||||||
// It handles configuration storage, retrieval, and validation for all system settings.
|
// It handles configuration storage, retrieval, and validation for all system settings.
|
||||||
type SettingService struct{}
|
type SettingService struct{}
|
||||||
|
|
||||||
func (s *SettingService) GetDefaultJSONConfig() (any, error) {
|
|
||||||
var jsonData any
|
|
||||||
err := json.Unmarshal([]byte(xrayTemplateConfig), &jsonData)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return jsonData, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SettingService) GetAllSetting() (*entity.AllSetting, error) {
|
func (s *SettingService) GetAllSetting() (*entity.AllSetting, error) {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
settings := make([]*model.Setting, 0)
|
settings := make([]*model.Setting, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user