remote.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. package runtime
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/json"
  6. "errors"
  7. "fmt"
  8. "io"
  9. "net"
  10. "net/http"
  11. "net/url"
  12. "strconv"
  13. "strings"
  14. "sync"
  15. "time"
  16. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  17. "github.com/mhsanaei/3x-ui/v3/internal/logger"
  18. "github.com/mhsanaei/3x-ui/v3/internal/util/netsafe"
  19. "github.com/mhsanaei/3x-ui/v3/internal/xray"
  20. )
  21. const remoteHTTPTimeout = 10 * time.Second
  22. type envelope struct {
  23. Success bool `json:"success"`
  24. Msg string `json:"msg"`
  25. Obj json.RawMessage `json:"obj"`
  26. }
  27. type Remote struct {
  28. node *model.Node
  29. mu sync.RWMutex
  30. remoteIDByTag map[string]int
  31. // Per-node client honoring the TLS verify mode, built once and reused; a
  32. // node config change drops the cached Remote so the next one rebuilds it.
  33. clientOnce sync.Once
  34. client *http.Client
  35. clientErr error
  36. }
  37. type RemoteInboundOption struct {
  38. Tag string `json:"tag"`
  39. Remark string `json:"remark"`
  40. Protocol model.Protocol `json:"protocol"`
  41. Port int `json:"port"`
  42. }
  43. func NewRemote(n *model.Node) *Remote {
  44. return &Remote{
  45. node: n,
  46. remoteIDByTag: make(map[string]int),
  47. }
  48. }
  49. func (r *Remote) Name() string { return "node:" + r.node.Name }
  50. // httpClient lazily builds and caches the per-node client honoring the TLS
  51. // verify mode, so Remote ops don't fall back to system CA on skip/pin (#5264).
  52. func (r *Remote) httpClient() (*http.Client, error) {
  53. r.clientOnce.Do(func() {
  54. r.client, r.clientErr = HTTPClientForNode(r.node)
  55. })
  56. return r.client, r.clientErr
  57. }
  58. func (r *Remote) baseURL() (string, error) {
  59. addr, err := netsafe.NormalizeHost(r.node.Address)
  60. if err != nil {
  61. return "", err
  62. }
  63. scheme := r.node.Scheme
  64. if scheme != "http" && scheme != "https" {
  65. scheme = "https"
  66. }
  67. if r.node.Port <= 0 || r.node.Port > 65535 {
  68. return "", fmt.Errorf("invalid node port %d", r.node.Port)
  69. }
  70. bp := r.node.BasePath
  71. if bp == "" {
  72. bp = "/"
  73. }
  74. if !strings.HasSuffix(bp, "/") {
  75. bp += "/"
  76. }
  77. u := &url.URL{
  78. Scheme: scheme,
  79. Host: net.JoinHostPort(addr, strconv.Itoa(r.node.Port)),
  80. Path: bp,
  81. }
  82. return u.String(), nil
  83. }
  84. func (r *Remote) do(ctx context.Context, method, path string, body any) (*envelope, error) {
  85. if r.node.ApiToken == "" {
  86. return nil, errors.New("node has no API token configured")
  87. }
  88. base, err := r.baseURL()
  89. if err != nil {
  90. return nil, err
  91. }
  92. target := base + strings.TrimPrefix(path, "/")
  93. var (
  94. reqBody io.Reader
  95. contentType string
  96. )
  97. switch b := body.(type) {
  98. case nil:
  99. case url.Values:
  100. reqBody = strings.NewReader(b.Encode())
  101. contentType = "application/x-www-form-urlencoded"
  102. default:
  103. buf, jerr := json.Marshal(b)
  104. if jerr != nil {
  105. return nil, fmt.Errorf("marshal body: %w", jerr)
  106. }
  107. reqBody = bytes.NewReader(buf)
  108. contentType = "application/json"
  109. }
  110. cctx, cancel := context.WithTimeout(netsafe.ContextWithAllowPrivate(ctx, r.node.AllowPrivateAddress), remoteHTTPTimeout)
  111. defer cancel()
  112. req, err := http.NewRequestWithContext(cctx, method, target, reqBody)
  113. if err != nil {
  114. return nil, err
  115. }
  116. req.Header.Set("Authorization", "Bearer "+r.node.ApiToken)
  117. req.Header.Set("Accept", "application/json")
  118. if contentType != "" {
  119. req.Header.Set("Content-Type", contentType)
  120. }
  121. client, err := r.httpClient()
  122. if err != nil {
  123. return nil, err
  124. }
  125. resp, err := client.Do(req)
  126. if err != nil {
  127. return nil, fmt.Errorf("%s %s: %w", method, path, err)
  128. }
  129. defer resp.Body.Close()
  130. raw, err := io.ReadAll(resp.Body)
  131. if err != nil {
  132. return nil, fmt.Errorf("read body: %w", err)
  133. }
  134. if resp.StatusCode != http.StatusOK {
  135. return nil, fmt.Errorf("%s %s: HTTP %d", method, path, resp.StatusCode)
  136. }
  137. var env envelope
  138. if err := json.Unmarshal(raw, &env); err != nil {
  139. return nil, fmt.Errorf("decode envelope: %w", err)
  140. }
  141. if !env.Success {
  142. return &env, fmt.Errorf("remote: %s", env.Msg)
  143. }
  144. return &env, nil
  145. }
  146. func (r *Remote) resolveRemoteID(ctx context.Context, tag string) (int, error) {
  147. if id, ok := r.cacheGetTag(tag); ok {
  148. return id, nil
  149. }
  150. if err := r.refreshRemoteIDs(ctx); err != nil {
  151. return 0, err
  152. }
  153. if id, ok := r.cacheGetTag(tag); ok {
  154. return id, nil
  155. }
  156. return 0, fmt.Errorf("remote inbound with tag %q not found on node %s", tag, r.node.Name)
  157. }
  158. // cacheGetTag looks up a remote inbound id by tag, tolerating an n<id>- prefix
  159. // that lives on only one of the two panels: the node may carry the bare tag
  160. // while the central panel stores the prefixed form, or vice versa.
  161. func (r *Remote) cacheGetTag(tag string) (int, bool) {
  162. if id, ok := r.cacheGet(tag); ok {
  163. return id, true
  164. }
  165. prefix := fmt.Sprintf("n%d-", r.node.Id)
  166. if stripped, found := strings.CutPrefix(tag, prefix); found {
  167. return r.cacheGet(stripped)
  168. }
  169. return r.cacheGet(prefix + tag)
  170. }
  171. func (r *Remote) cacheGet(tag string) (int, bool) {
  172. r.mu.RLock()
  173. defer r.mu.RUnlock()
  174. id, ok := r.remoteIDByTag[tag]
  175. return id, ok
  176. }
  177. func (r *Remote) cacheSet(tag string, id int) {
  178. r.mu.Lock()
  179. defer r.mu.Unlock()
  180. r.remoteIDByTag[tag] = id
  181. }
  182. func (r *Remote) cacheDel(tag string) {
  183. r.mu.Lock()
  184. defer r.mu.Unlock()
  185. delete(r.remoteIDByTag, tag)
  186. }
  187. func (r *Remote) ListRemoteTags(ctx context.Context) ([]string, error) {
  188. if err := r.refreshRemoteIDs(ctx); err != nil {
  189. return nil, err
  190. }
  191. r.mu.RLock()
  192. defer r.mu.RUnlock()
  193. tags := make([]string, 0, len(r.remoteIDByTag))
  194. for tag := range r.remoteIDByTag {
  195. tags = append(tags, tag)
  196. }
  197. return tags, nil
  198. }
  199. func (r *Remote) ListInboundOptions(ctx context.Context) ([]RemoteInboundOption, error) {
  200. env, err := r.do(ctx, http.MethodGet, "panel/api/inbounds/list", nil)
  201. if err != nil {
  202. return nil, err
  203. }
  204. var list []RemoteInboundOption
  205. if err := json.Unmarshal(env.Obj, &list); err != nil {
  206. return nil, fmt.Errorf("decode inbound list: %w", err)
  207. }
  208. return list, nil
  209. }
  210. func (r *Remote) refreshRemoteIDs(ctx context.Context) error {
  211. env, err := r.do(ctx, http.MethodGet, "panel/api/inbounds/list", nil)
  212. if err != nil {
  213. return err
  214. }
  215. var list []struct {
  216. Id int `json:"id"`
  217. Tag string `json:"tag"`
  218. }
  219. if err := json.Unmarshal(env.Obj, &list); err != nil {
  220. return fmt.Errorf("decode inbound list: %w", err)
  221. }
  222. next := make(map[string]int, len(list))
  223. for _, ib := range list {
  224. if ib.Tag == "" {
  225. continue
  226. }
  227. next[ib.Tag] = ib.Id
  228. }
  229. r.mu.Lock()
  230. r.remoteIDByTag = next
  231. r.mu.Unlock()
  232. return nil
  233. }
  234. func (r *Remote) AddInbound(ctx context.Context, ib *model.Inbound) error {
  235. payload := wireInbound(ib)
  236. env, err := r.do(ctx, http.MethodPost, "panel/api/inbounds/add", payload)
  237. if err != nil {
  238. return err
  239. }
  240. var created struct {
  241. Id int `json:"id"`
  242. Tag string `json:"tag"`
  243. }
  244. if len(env.Obj) > 0 {
  245. if err := json.Unmarshal(env.Obj, &created); err == nil && created.Id > 0 && created.Tag != "" {
  246. r.cacheSet(created.Tag, created.Id)
  247. }
  248. }
  249. return nil
  250. }
  251. func (r *Remote) DelInbound(ctx context.Context, ib *model.Inbound) error {
  252. id, err := r.resolveRemoteID(ctx, ib.Tag)
  253. if err != nil {
  254. logger.Warning("remote DelInbound: tag", ib.Tag, "not found on", r.node.Name)
  255. return nil
  256. }
  257. if _, err := r.do(ctx, http.MethodPost, "panel/api/inbounds/del/"+strconv.Itoa(id), nil); err != nil {
  258. return err
  259. }
  260. r.cacheDel(ib.Tag)
  261. return nil
  262. }
  263. func (r *Remote) UpdateInbound(ctx context.Context, oldIb, newIb *model.Inbound) error {
  264. id, err := r.resolveRemoteID(ctx, oldIb.Tag)
  265. if err != nil {
  266. return r.AddInbound(ctx, newIb)
  267. }
  268. payload := wireInbound(newIb)
  269. if _, err := r.do(ctx, http.MethodPost, "panel/api/inbounds/update/"+strconv.Itoa(id), payload); err != nil {
  270. return err
  271. }
  272. if oldIb.Tag != newIb.Tag {
  273. r.cacheDel(oldIb.Tag)
  274. }
  275. r.cacheSet(newIb.Tag, id)
  276. return nil
  277. }
  278. func (r *Remote) AddUser(ctx context.Context, ib *model.Inbound, _ map[string]any) error {
  279. return r.UpdateInbound(ctx, ib, ib)
  280. }
  281. func (r *Remote) RemoveUser(ctx context.Context, ib *model.Inbound, _ string) error {
  282. return r.UpdateInbound(ctx, ib, ib)
  283. }
  284. func (r *Remote) AddClient(ctx context.Context, ib *model.Inbound, client model.Client) error {
  285. id, err := r.resolveRemoteID(ctx, ib.Tag)
  286. if err != nil {
  287. return fmt.Errorf("remote AddClient: resolve tag %q: %w", ib.Tag, err)
  288. }
  289. payload := map[string]any{
  290. "client": client,
  291. "inboundIds": []int{id},
  292. }
  293. if _, err := r.do(ctx, http.MethodPost, "panel/api/clients/add", payload); err != nil {
  294. return err
  295. }
  296. return nil
  297. }
  298. func (r *Remote) DeleteUser(ctx context.Context, ib *model.Inbound, email string) error {
  299. if email == "" {
  300. return nil
  301. }
  302. id, err := r.resolveRemoteID(ctx, ib.Tag)
  303. if err != nil {
  304. return nil
  305. }
  306. body := map[string]any{"inboundIds": []int{id}}
  307. _, err = r.do(ctx, http.MethodPost,
  308. "panel/api/clients/"+url.PathEscape(email)+"/detach", body)
  309. if err == nil {
  310. return nil
  311. }
  312. if strings.Contains(strings.ToLower(err.Error()), "not found") {
  313. return nil
  314. }
  315. return err
  316. }
  317. func (r *Remote) UpdateUser(ctx context.Context, ib *model.Inbound, oldEmail string, payload model.Client) error {
  318. if oldEmail == "" {
  319. oldEmail = payload.Email
  320. }
  321. id, err := r.resolveRemoteID(ctx, ib.Tag)
  322. if err != nil {
  323. return err
  324. }
  325. path := "panel/api/clients/update/" + url.PathEscape(oldEmail) +
  326. "?inboundIds=" + strconv.Itoa(id)
  327. if _, err := r.do(ctx, http.MethodPost, path, payload); err != nil {
  328. return err
  329. }
  330. return nil
  331. }
  332. func (r *Remote) RestartXray(ctx context.Context) error {
  333. _, err := r.do(ctx, http.MethodPost, "panel/api/server/restartXrayService", nil)
  334. return err
  335. }
  336. // UpdatePanel asks the node to run its own official self-updater (update.sh)
  337. // and restart onto the latest release. The node returns as soon as the job is
  338. // launched; the new version surfaces on the next heartbeat.
  339. func (r *Remote) UpdatePanel(ctx context.Context) error {
  340. _, err := r.do(ctx, http.MethodPost, "panel/api/server/updatePanel", nil)
  341. return err
  342. }
  343. // WebCertFiles holds a node's own web TLS certificate and key file paths.
  344. type WebCertFiles struct {
  345. WebCertFile string `json:"webCertFile"`
  346. WebKeyFile string `json:"webKeyFile"`
  347. }
  348. // GetWebCertFiles fetches the node's own web TLS certificate/key file paths so
  349. // the central panel can offer them as the "Set Cert from Panel" default for a
  350. // node-assigned inbound — those paths exist on the node, the central panel's
  351. // don't. See issue #4854.
  352. func (r *Remote) GetWebCertFiles(ctx context.Context) (*WebCertFiles, error) {
  353. env, err := r.do(ctx, http.MethodGet, "panel/api/server/getWebCertFiles", nil)
  354. if err != nil {
  355. return nil, err
  356. }
  357. var files WebCertFiles
  358. if err := json.Unmarshal(env.Obj, &files); err != nil {
  359. return nil, fmt.Errorf("decode web cert files: %w", err)
  360. }
  361. return &files, nil
  362. }
  363. // GetDescendants fetches the node's read-only summaries of the nodes IT
  364. // manages, so this panel can surface them as transitive sub-nodes in a chained
  365. // topology (#4983). Best-effort: an old-build node without the endpoint returns
  366. // an error the caller ignores.
  367. func (r *Remote) GetDescendants(ctx context.Context) ([]model.NodeSummary, error) {
  368. env, err := r.do(ctx, http.MethodGet, "panel/api/server/descendants", nil)
  369. if err != nil {
  370. return nil, err
  371. }
  372. var out []model.NodeSummary
  373. if len(env.Obj) > 0 {
  374. if err := json.Unmarshal(env.Obj, &out); err != nil {
  375. return nil, fmt.Errorf("decode descendants: %w", err)
  376. }
  377. }
  378. return out, nil
  379. }
  380. func (r *Remote) ResetClientTraffic(ctx context.Context, _ *model.Inbound, email string) error {
  381. _, err := r.do(ctx, http.MethodPost,
  382. "panel/api/clients/resetTraffic/"+url.PathEscape(email), nil)
  383. return err
  384. }
  385. func (r *Remote) ResetAllTraffics(ctx context.Context) error {
  386. _, err := r.do(ctx, http.MethodPost, "panel/api/inbounds/resetAllTraffics", nil)
  387. return err
  388. }
  389. func (r *Remote) ResetInboundTraffic(ctx context.Context, ib *model.Inbound) error {
  390. _, err := r.do(ctx, http.MethodPost, fmt.Sprintf("panel/api/inbounds/%d/resetTraffic", ib.Id), nil)
  391. return err
  392. }
  393. type TrafficSnapshot struct {
  394. Inbounds []*model.Inbound
  395. OnlineEmails []string
  396. // OnlineTree is the node's GUID-keyed online subtree (its own clients under
  397. // its panelGuid plus every descendant under theirs). Preferred over the flat
  398. // OnlineEmails so the master can attribute deeply nested clients to the real
  399. // node across a chain (#4983). Empty when the node is an old build without
  400. // the per-GUID endpoint — OnlineEmails is the fallback then.
  401. OnlineTree map[string][]string
  402. LastOnlineMap map[string]int64
  403. }
  404. func (r *Remote) FetchTrafficSnapshot(ctx context.Context) (*TrafficSnapshot, error) {
  405. snap := &TrafficSnapshot{LastOnlineMap: map[string]int64{}}
  406. envList, err := r.do(ctx, http.MethodGet, "panel/api/inbounds/list", nil)
  407. if err != nil {
  408. return nil, err
  409. }
  410. if err := json.Unmarshal(envList.Obj, &snap.Inbounds); err != nil {
  411. return nil, fmt.Errorf("decode inbound list: %w", err)
  412. }
  413. // Prefer the GUID-keyed subtree; fall back to the flat list only when the
  414. // node is an old build without the per-GUID endpoint (#4983).
  415. envTree, err := r.do(ctx, http.MethodPost, "panel/api/clients/onlinesByGuid", nil)
  416. if err == nil && len(envTree.Obj) > 0 {
  417. _ = json.Unmarshal(envTree.Obj, &snap.OnlineTree)
  418. }
  419. if len(snap.OnlineTree) == 0 {
  420. envOnlines, err := r.do(ctx, http.MethodPost, "panel/api/clients/onlines", nil)
  421. if err != nil {
  422. logger.Warning("remote", r.node.Name, "onlines fetch failed:", err)
  423. } else if len(envOnlines.Obj) > 0 {
  424. _ = json.Unmarshal(envOnlines.Obj, &snap.OnlineEmails)
  425. }
  426. }
  427. envLastOnline, err := r.do(ctx, http.MethodPost, "panel/api/clients/lastOnline", nil)
  428. if err != nil {
  429. logger.Warning("remote", r.node.Name, "lastOnline fetch failed:", err)
  430. } else if len(envLastOnline.Obj) > 0 {
  431. _ = json.Unmarshal(envLastOnline.Obj, &snap.LastOnlineMap)
  432. }
  433. return snap, nil
  434. }
  435. // PushGlobalClientTraffics sends this panel's aggregated per-client usage to
  436. // the node, tagged with this panel's GUID so the node keeps one row per
  437. // pushing master. Display/enforcement input on the node only — the node never
  438. // folds these into the counters it reports back, so this panel's (and any
  439. // other master's) delta accounting over the node snapshot stays intact.
  440. func (r *Remote) PushGlobalClientTraffics(ctx context.Context, masterGuid string, traffics []*xray.ClientTraffic) error {
  441. payload := map[string]any{
  442. "masterGuid": masterGuid,
  443. "traffics": traffics,
  444. }
  445. _, err := r.do(ctx, http.MethodPost, "panel/api/inbounds/pushClientTraffics", payload)
  446. return err
  447. }
  448. func wireInbound(ib *model.Inbound) url.Values {
  449. v := url.Values{}
  450. v.Set("total", strconv.FormatInt(ib.Total, 10))
  451. v.Set("remark", ib.Remark)
  452. v.Set("subSortIndex", strconv.Itoa(ib.SubSortIndex))
  453. v.Set("enable", strconv.FormatBool(ib.Enable))
  454. v.Set("expiryTime", strconv.FormatInt(ib.ExpiryTime, 10))
  455. v.Set("listen", ib.Listen)
  456. v.Set("port", strconv.Itoa(ib.Port))
  457. v.Set("protocol", string(ib.Protocol))
  458. v.Set("settings", ib.Settings)
  459. v.Set("streamSettings", sanitizeStreamSettingsForRemote(ib.StreamSettings))
  460. v.Set("tag", ib.Tag)
  461. v.Set("sniffing", ib.Sniffing)
  462. shareAddrStrategy := strings.TrimSpace(ib.ShareAddrStrategy)
  463. switch shareAddrStrategy {
  464. case "listen", "custom":
  465. default:
  466. shareAddrStrategy = "node"
  467. }
  468. v.Set("shareAddrStrategy", shareAddrStrategy)
  469. v.Set("shareAddr", ib.ShareAddr)
  470. if ib.TrafficReset != "" {
  471. v.Set("trafficReset", ib.TrafficReset)
  472. }
  473. return v
  474. }
  475. // sanitizeStreamSettingsForRemote strips file-based TLS certificate paths
  476. // from the StreamSettings before sending to a remote node, but ONLY when
  477. // inline certificate content (certificate / key) is also present in the same
  478. // entry. In that case the file paths are redundant and stripping them avoids
  479. // confusion when the central panel's local paths don't exist on the remote.
  480. //
  481. // When a certificate entry contains ONLY file paths (no inline content) the
  482. // paths are left untouched: the user explicitly entered paths that exist on
  483. // the remote node's filesystem, and removing them would leave Xray with TLS
  484. // configured but no certificate, causing Xray to crash on the remote node.
  485. func sanitizeStreamSettingsForRemote(streamSettings string) string {
  486. if streamSettings == "" {
  487. return streamSettings
  488. }
  489. var stream map[string]any
  490. if err := json.Unmarshal([]byte(streamSettings), &stream); err != nil {
  491. return streamSettings
  492. }
  493. tlsSettings, ok := stream["tlsSettings"].(map[string]any)
  494. if !ok {
  495. return streamSettings
  496. }
  497. certificates, ok := tlsSettings["certificates"].([]any)
  498. if !ok {
  499. return streamSettings
  500. }
  501. changed := false
  502. for _, cert := range certificates {
  503. c, ok := cert.(map[string]any)
  504. if !ok {
  505. continue
  506. }
  507. // Only strip file paths when inline content is present so that the
  508. // remote Xray still has a valid certificate to use.
  509. hasCertFile := c["certificateFile"] != nil && c["certificateFile"] != ""
  510. hasKeyFile := c["keyFile"] != nil && c["keyFile"] != ""
  511. hasCertInline := isNonEmptySlice(c["certificate"])
  512. hasKeyInline := isNonEmptySlice(c["key"])
  513. if hasCertFile && hasCertInline {
  514. delete(c, "certificateFile")
  515. changed = true
  516. }
  517. if hasKeyFile && hasKeyInline {
  518. delete(c, "keyFile")
  519. changed = true
  520. }
  521. }
  522. if !changed {
  523. return streamSettings
  524. }
  525. out, err := json.Marshal(stream)
  526. if err != nil {
  527. return streamSettings
  528. }
  529. return string(out)
  530. }
  531. // isNonEmptySlice reports whether v is a non-nil, non-empty JSON array value.
  532. func isNonEmptySlice(v any) bool {
  533. s, ok := v.([]any)
  534. return ok && len(s) > 0
  535. }
  536. func (r *Remote) FetchAllClientIps(ctx context.Context) ([]model.InboundClientIps, error) {
  537. env, err := r.do(ctx, http.MethodGet, "panel/api/server/clientIps", nil)
  538. if err != nil {
  539. return nil, err
  540. }
  541. var ips []model.InboundClientIps
  542. if len(env.Obj) > 0 {
  543. if err := json.Unmarshal(env.Obj, &ips); err != nil {
  544. return nil, fmt.Errorf("decode client ips: %w", err)
  545. }
  546. }
  547. return ips, nil
  548. }
  549. func (r *Remote) PushAllClientIps(ctx context.Context, ips []model.InboundClientIps) error {
  550. _, err := r.do(ctx, http.MethodPost, "panel/api/server/clientIps", ips)
  551. return err
  552. }