Apply inbounds on nodes via Xray with Reality settings and client sync.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
orohi
2026-07-29 05:11:45 +03:00
co-authored by Cursor
parent c41bae9852
commit 20a20168b6
15 changed files with 1081 additions and 63 deletions
+15 -2
View File
@@ -13,7 +13,7 @@ import (
"time"
)
const defaultVersion = "0.1.0"
const defaultVersion = "0.2.0"
type Agent struct {
name string
@@ -54,6 +54,7 @@ func main() {
config: map[string]any{},
}
a.loadConfig(filepath.Join(dataDir, "config.json"))
a.applyXray(a.config)
mux := http.NewServeMux()
mux.HandleFunc("/health", a.auth(a.health))
@@ -186,7 +187,12 @@ func (a *Agent) configHandler(w http.ResponseWriter, r *http.Request) {
a.config = cfg
a.mu.Unlock()
_ = a.saveConfig(filepath.Join(a.dataDir, "config.json"))
log.Printf("config updated: installed=%v enabled=%v", stringList(cfg, "protocols_installed"), stringList(cfg, "protocols_enabled"))
a.applyXray(cfg)
log.Printf("config updated: installed=%v enabled=%v inbounds=%d",
stringList(cfg, "protocols_installed"),
stringList(cfg, "protocols_enabled"),
len(anySlice(cfg["inbounds"])),
)
writeJSON(w, map[string]any{"ok": true})
default:
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
@@ -218,3 +224,10 @@ func writeJSON(w http.ResponseWriter, v any) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(v)
}
func anySlice(v any) []any {
if arr, ok := v.([]any); ok {
return arr
}
return nil
}