mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-30 06:57:14 +00:00
refactor: replace custom geo manager with Xray-core native geodata auto-update
Remove the panel-side custom geo download feature (service, controller, /panel/api/custom-geo/* endpoints, CustomGeoResource model, UI tab) in favor of Xray-core's native geodata section (https://xtls.github.io/config/geodata.html). - pass the top-level "geodata" key through xray.Config so it survives the template round-trip into the generated config - add a Geodata Auto-Update section to the Xray Updates modal that edits geodata (cron schedule, download outbound, asset list) in the config template and restarts Xray on save - previously downloaded geo files in the bin folder keep working in ext: routing rules; the orphaned custom_geo_resources table is left in place so existing source URLs stay recoverable
This commit is contained in:
@@ -3,8 +3,6 @@ package integration
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -17,7 +15,7 @@ func recordingProxy(t *testing.T, hits *int64) *httptest.Server {
|
||||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
atomic.AddInt64(hits, 1)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(make([]byte, minDatBytes+1))
|
||||
_, _ = w.Write([]byte("ok"))
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -26,7 +24,7 @@ func originServer(t *testing.T, hits *int64) *httptest.Server {
|
||||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
atomic.AddInt64(hits, 1)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(make([]byte, minDatBytes+1))
|
||||
_, _ = w.Write([]byte("ok"))
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -51,53 +49,3 @@ func TestPanelProxy_NetproxyHelperRoutesThroughProxy(t *testing.T) {
|
||||
t.Fatalf("expected panel proxy to be hit once, got %d (origin hits=%d)", proxyHits, originHits)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPanelProxy_CustomGeoDownloadUsesProxy(t *testing.T) {
|
||||
disableSSRFCheck(t)
|
||||
|
||||
var proxyHits, originHits int64
|
||||
proxy := recordingProxy(t, &proxyHits)
|
||||
defer proxy.Close()
|
||||
origin := originServer(t, &originHits)
|
||||
defer origin.Close()
|
||||
|
||||
dir := t.TempDir()
|
||||
t.Setenv("XUI_BIN_FOLDER", dir)
|
||||
dest := filepath.Join(dir, "geosite_repro.dat")
|
||||
|
||||
s := CustomGeoService{getPanelProxy: func() (string, error) { return proxy.URL, nil }}
|
||||
if _, _, err := s.downloadToPath(origin.URL, dest, ""); err != nil {
|
||||
t.Fatalf("download failed: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(dest); err != nil {
|
||||
t.Fatalf("expected file to be written: %v", err)
|
||||
}
|
||||
|
||||
if got := atomic.LoadInt64(&proxyHits); got != 1 {
|
||||
t.Fatalf("custom geo download did not route through the Panel Network Proxy "+
|
||||
"(proxy hits=%d, origin hits=%d)", got, atomic.LoadInt64(&originHits))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPanelProxy_CustomGeoDownloadDirectWhenUnset(t *testing.T) {
|
||||
disableSSRFCheck(t)
|
||||
|
||||
var proxyHits, originHits int64
|
||||
proxy := recordingProxy(t, &proxyHits)
|
||||
defer proxy.Close()
|
||||
origin := originServer(t, &originHits)
|
||||
defer origin.Close()
|
||||
|
||||
dir := t.TempDir()
|
||||
t.Setenv("XUI_BIN_FOLDER", dir)
|
||||
dest := filepath.Join(dir, "geosite_direct.dat")
|
||||
|
||||
s := CustomGeoService{}
|
||||
if _, _, err := s.downloadToPath(origin.URL, dest, ""); err != nil {
|
||||
t.Fatalf("download failed: %v", err)
|
||||
}
|
||||
if atomic.LoadInt64(&proxyHits) != 0 || atomic.LoadInt64(&originHits) != 1 {
|
||||
t.Fatalf("expected direct connection (proxy=0, origin=1), got proxy=%d origin=%d",
|
||||
atomic.LoadInt64(&proxyHits), atomic.LoadInt64(&originHits))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user