server.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. package controller
  2. import (
  3. "fmt"
  4. "net/http"
  5. "regexp"
  6. "slices"
  7. "strconv"
  8. "time"
  9. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  10. "github.com/mhsanaei/3x-ui/v3/internal/logger"
  11. "github.com/mhsanaei/3x-ui/v3/internal/web/entity"
  12. "github.com/mhsanaei/3x-ui/v3/internal/web/global"
  13. "github.com/mhsanaei/3x-ui/v3/internal/web/service"
  14. "github.com/mhsanaei/3x-ui/v3/internal/web/service/panel"
  15. "github.com/mhsanaei/3x-ui/v3/internal/web/websocket"
  16. "github.com/gin-gonic/gin"
  17. )
  18. var filenameRegex = regexp.MustCompile(`^[a-zA-Z0-9_\-.]+$`)
  19. // ServerController handles server management and status-related operations.
  20. type ServerController struct {
  21. BaseController
  22. serverService service.ServerService
  23. settingService service.SettingService
  24. panelService panel.PanelService
  25. xrayMetricsService service.XrayMetricsService
  26. }
  27. // NewServerController creates a new ServerController, initializes routes, and starts background tasks.
  28. func NewServerController(g *gin.RouterGroup) *ServerController {
  29. a := &ServerController{}
  30. service.RestoreSystemMetrics()
  31. a.initRouter(g)
  32. a.startTask()
  33. return a
  34. }
  35. // initRouter sets up the routes for server status, Xray management, and utility endpoints.
  36. func (a *ServerController) initRouter(g *gin.RouterGroup) {
  37. g.GET("/status", a.status)
  38. g.GET("/cpuHistory/:bucket", a.getCpuHistoryBucket)
  39. g.GET("/history/:metric/:bucket", a.getMetricHistoryBucket)
  40. g.GET("/xrayMetricsState", a.getXrayMetricsState)
  41. g.GET("/xrayMetricsHistory/:metric/:bucket", a.getXrayMetricsHistoryBucket)
  42. g.GET("/xrayObservatory", a.getXrayObservatory)
  43. g.GET("/xrayObservatoryHistory/:tag/:bucket", a.getXrayObservatoryHistoryBucket)
  44. g.GET("/getXrayVersion", a.getXrayVersion)
  45. g.GET("/getPanelUpdateInfo", a.getPanelUpdateInfo)
  46. g.GET("/getUpdateStatus", a.getUpdateStatus)
  47. g.GET("/getConfigJson", a.getConfigJson)
  48. g.GET("/getDb", a.getDb)
  49. g.GET("/getMigration", a.getMigration)
  50. g.GET("/getNewUUID", a.getNewUUID)
  51. g.GET("/getWebCertFiles", a.getWebCertFiles)
  52. g.GET("/descendants", a.descendants)
  53. g.GET("/getNewX25519Cert", a.getNewX25519Cert)
  54. g.GET("/getNewmldsa65", a.getNewmldsa65)
  55. g.GET("/getNewmlkem768", a.getNewmlkem768)
  56. g.GET("/getNewVlessEnc", a.getNewVlessEnc)
  57. g.GET("/clientIps", a.getClientIps)
  58. g.GET("/fail2banStatus", a.getFail2banStatus)
  59. g.POST("/stopXrayService", a.stopXrayService)
  60. g.POST("/restartXrayService", a.restartXrayService)
  61. g.POST("/installXray/:version", a.installXray)
  62. g.POST("/updatePanel", a.updatePanel)
  63. g.POST("/setUpdateChannel", a.setUpdateChannel)
  64. g.POST("/updateGeofile", a.updateGeofile)
  65. g.POST("/updateGeofile/:fileName", a.updateGeofile)
  66. g.POST("/logs/:count", a.getLogs)
  67. g.POST("/xraylogs/:count", a.getXrayLogs)
  68. g.POST("/amneziawglogs/:count", a.getAmneziaWGLogs)
  69. g.POST("/importDB", a.importDB)
  70. g.POST("/getNewEchCert", a.getNewEchCert)
  71. g.POST("/getCertHash", a.getCertHash)
  72. g.POST("/getRemoteCertHash", a.getRemoteCertHash)
  73. g.POST("/scanRealityTarget", a.scanRealityTarget)
  74. g.POST("/scanRealityTargets", a.scanRealityTargets)
  75. g.POST("/clientIps", a.setClientIps)
  76. }
  77. // startTask registers the @2s ticker that refreshes server status, samples
  78. // xray metrics, and pushes the new snapshot to all websocket subscribers.
  79. // State + sampling live in ServerService; the controller only orchestrates
  80. // the cross-service side effects (xrayMetrics sample + websocket broadcast).
  81. func (a *ServerController) startTask() {
  82. c := global.GetWebServer().GetCron()
  83. _, _ = c.AddFunc("@every 2s", func() {
  84. status := a.serverService.RefreshStatus()
  85. if status == nil {
  86. return
  87. }
  88. a.xrayMetricsService.Sample(time.Now())
  89. websocket.BroadcastStatus(status)
  90. })
  91. _, _ = c.AddFunc("@every 1m", func() {
  92. if err := service.PersistSystemMetrics(); err != nil {
  93. logger.Warning("persist system metrics failed:", err)
  94. }
  95. })
  96. }
  97. // status returns the current server status information.
  98. func (a *ServerController) status(c *gin.Context) { jsonObj(c, a.serverService.LastStatus(), nil) }
  99. func (a *ServerController) getFail2banStatus(c *gin.Context) {
  100. jsonObj(c, a.serverService.GetFail2banStatus(), nil)
  101. }
  102. func parseHistoryBucket(c *gin.Context) (int, bool) {
  103. bucket, err := strconv.Atoi(c.Param("bucket"))
  104. if err != nil || bucket <= 0 || !service.IsAllowedHistoryBucket(bucket) {
  105. jsonMsg(c, "invalid bucket", fmt.Errorf("unsupported bucket"))
  106. return 0, false
  107. }
  108. return bucket, true
  109. }
  110. // getCpuHistoryBucket retrieves aggregated CPU usage history based on the specified time bucket.
  111. // Kept for back-compat; new callers should use /history/cpu/:bucket which
  112. // returns {"t","v"} (uniform across all metrics) instead of {"t","cpu"}.
  113. func (a *ServerController) getCpuHistoryBucket(c *gin.Context) {
  114. bucket, ok := parseHistoryBucket(c)
  115. if !ok {
  116. return
  117. }
  118. jsonObj(c, a.serverService.AggregateCpuHistory(bucket, 60), nil)
  119. }
  120. // getMetricHistoryBucket returns up to 60 buckets of history for a single
  121. // system metric (cpu, mem, netUp, netDown, online, load1/5/15). The
  122. // SystemHistoryModal calls one endpoint per active tab.
  123. func (a *ServerController) getMetricHistoryBucket(c *gin.Context) {
  124. metric := c.Param("metric")
  125. if !slices.Contains(service.SystemMetricKeys, metric) {
  126. jsonMsg(c, "invalid metric", fmt.Errorf("unknown metric"))
  127. return
  128. }
  129. bucket, ok := parseHistoryBucket(c)
  130. if !ok {
  131. return
  132. }
  133. jsonObj(c, a.serverService.AggregateSystemMetric(metric, bucket, 60), nil)
  134. }
  135. func (a *ServerController) getXrayMetricsState(c *gin.Context) {
  136. jsonObj(c, a.xrayMetricsService.State(), nil)
  137. }
  138. func (a *ServerController) getXrayMetricsHistoryBucket(c *gin.Context) {
  139. metric := c.Param("metric")
  140. if !slices.Contains(service.XrayMetricKeys, metric) {
  141. jsonMsg(c, "invalid metric", fmt.Errorf("unknown metric"))
  142. return
  143. }
  144. bucket, ok := parseHistoryBucket(c)
  145. if !ok {
  146. return
  147. }
  148. jsonObj(c, a.xrayMetricsService.AggregateMetric(metric, bucket, 60), nil)
  149. }
  150. func (a *ServerController) getXrayObservatory(c *gin.Context) {
  151. jsonObj(c, a.xrayMetricsService.ObservatorySnapshot(), nil)
  152. }
  153. func (a *ServerController) getXrayObservatoryHistoryBucket(c *gin.Context) {
  154. tag := c.Param("tag")
  155. if !a.xrayMetricsService.HasObservatoryTag(tag) {
  156. jsonMsg(c, "invalid tag", fmt.Errorf("unknown observatory tag"))
  157. return
  158. }
  159. bucket, ok := parseHistoryBucket(c)
  160. if !ok {
  161. return
  162. }
  163. jsonObj(c, a.xrayMetricsService.AggregateObservatory(tag, bucket, 60), nil)
  164. }
  165. func (a *ServerController) getXrayVersion(c *gin.Context) {
  166. versions, err := a.serverService.GetXrayVersionsCached()
  167. if err != nil {
  168. jsonMsg(c, I18nWeb(c, "getVersion"), err)
  169. return
  170. }
  171. jsonObj(c, versions, nil)
  172. }
  173. // getPanelUpdateInfo retrieves the current and latest panel version.
  174. func (a *ServerController) getPanelUpdateInfo(c *gin.Context) {
  175. info, err := a.panelService.GetUpdateInfo()
  176. if err != nil {
  177. logger.Debug("panel update check failed:", err)
  178. c.JSON(http.StatusOK, entity.Msg{Success: false})
  179. return
  180. }
  181. jsonObj(c, info, nil)
  182. }
  183. // installXray installs or updates Xray to the specified version.
  184. func (a *ServerController) installXray(c *gin.Context) {
  185. version := c.Param("version")
  186. err := a.serverService.UpdateXray(version)
  187. jsonMsg(c, I18nWeb(c, "pages.index.xraySwitchVersionPopover"), err)
  188. }
  189. // updatePanel starts a panel self-update. With no "dev" form value it follows
  190. // this panel's own channel setting; an explicit "dev" (sent by the master node
  191. // updater) overrides it for this run. The response's runId identifies this
  192. // update for a later getUpdateStatus poll.
  193. func (a *ServerController) updatePanel(c *gin.Context) {
  194. devParam := c.PostForm("dev")
  195. var runID int64
  196. var err error
  197. if devParam == "" {
  198. runID, err = a.panelService.StartUpdate()
  199. } else {
  200. dev, perr := strconv.ParseBool(devParam)
  201. if perr != nil {
  202. jsonMsg(c, "invalid data", perr)
  203. return
  204. }
  205. runID, err = a.panelService.StartUpdateChannel(dev)
  206. }
  207. var obj any
  208. if err == nil {
  209. obj = gin.H{"runId": strconv.FormatInt(runID, 10)}
  210. }
  211. jsonMsgObj(c, I18nWeb(c, "pages.index.panelUpdateStartedPopover"), obj, err)
  212. }
  213. // getUpdateStatus reports the outcome of the most recently launched panel
  214. // self-update (see updatePanel). Compare the returned runId against the one
  215. // updatePanel returned to tell this run's result apart from a stale one.
  216. func (a *ServerController) getUpdateStatus(c *gin.Context) {
  217. jsonObj(c, a.panelService.GetUpdateStatus(), nil)
  218. }
  219. // setUpdateChannel toggles whether self-update tracks the rolling dev release.
  220. func (a *ServerController) setUpdateChannel(c *gin.Context) {
  221. dev, err := strconv.ParseBool(c.PostForm("dev"))
  222. if err != nil {
  223. jsonMsg(c, "invalid data", err)
  224. return
  225. }
  226. err = a.settingService.SetDevChannelEnable(dev)
  227. jsonMsg(c, I18nWeb(c, "pages.index.updateChannelChanged"), err)
  228. }
  229. // updateGeofile updates the specified geo file for Xray.
  230. func (a *ServerController) updateGeofile(c *gin.Context) {
  231. fileName := c.Param("fileName")
  232. if fileName != "" && !a.serverService.IsValidGeofileName(fileName) {
  233. jsonMsg(c, I18nWeb(c, "pages.index.geofileUpdatePopover"),
  234. fmt.Errorf("invalid filename: contains unsafe characters or path traversal patterns"))
  235. return
  236. }
  237. err := a.serverService.UpdateGeofile(fileName)
  238. jsonMsg(c, I18nWeb(c, "pages.index.geofileUpdatePopover"), err)
  239. }
  240. // stopXrayService stops the Xray service.
  241. func (a *ServerController) stopXrayService(c *gin.Context) {
  242. err := a.serverService.StopXrayService()
  243. if err != nil {
  244. jsonMsg(c, I18nWeb(c, "pages.xray.stopError"), err)
  245. websocket.BroadcastXrayState("error", err.Error())
  246. return
  247. }
  248. jsonMsg(c, I18nWeb(c, "pages.xray.stopSuccess"), err)
  249. websocket.BroadcastXrayState("stop", "")
  250. websocket.BroadcastNotification(
  251. I18nWeb(c, "pages.xray.stopSuccess"),
  252. "Xray service has been stopped",
  253. "warning",
  254. )
  255. }
  256. // restartXrayService restarts the Xray service.
  257. func (a *ServerController) restartXrayService(c *gin.Context) {
  258. err := a.serverService.RestartXrayService()
  259. if err != nil {
  260. jsonMsg(c, I18nWeb(c, "pages.xray.restartError"), err)
  261. websocket.BroadcastXrayState("error", err.Error())
  262. return
  263. }
  264. jsonMsg(c, I18nWeb(c, "pages.xray.restartSuccess"), err)
  265. websocket.BroadcastXrayState("running", "")
  266. websocket.BroadcastNotification(
  267. I18nWeb(c, "pages.xray.restartSuccess"),
  268. "Xray service has been restarted successfully",
  269. "success",
  270. )
  271. }
  272. // getLogs retrieves the application logs based on count, level, and syslog filters.
  273. func (a *ServerController) getLogs(c *gin.Context) {
  274. logs := a.serverService.GetLogs(c.Param("count"), c.PostForm("level"), c.PostForm("syslog"))
  275. jsonObj(c, logs, nil)
  276. }
  277. // getXrayLogs retrieves Xray logs with filtering options for direct, blocked, and proxy traffic.
  278. func (a *ServerController) getXrayLogs(c *gin.Context) {
  279. freedoms, blackholes := a.serverService.GetDefaultLogOutboundTags()
  280. logs := a.serverService.GetXrayLogs(
  281. c.Param("count"),
  282. c.PostForm("filter"),
  283. c.PostForm("showDirect"),
  284. c.PostForm("showBlocked"),
  285. c.PostForm("showProxy"),
  286. freedoms,
  287. blackholes,
  288. )
  289. jsonObj(c, logs, nil)
  290. }
  291. // getAmneziaWGLogs retrieves the live AmneziaWG peer activity and the panel's
  292. // own AmneziaWG event lines, optionally narrowed by a free-text filter.
  293. func (a *ServerController) getAmneziaWGLogs(c *gin.Context) {
  294. logs := a.serverService.GetAmneziaWGLogs(c.Param("count"), c.PostForm("filter"))
  295. jsonObj(c, logs, nil)
  296. }
  297. // getConfigJson retrieves the Xray configuration as JSON.
  298. func (a *ServerController) getConfigJson(c *gin.Context) {
  299. configJson, err := a.serverService.GetConfigJson()
  300. if err != nil {
  301. jsonMsg(c, I18nWeb(c, "pages.index.getConfigError"), err)
  302. return
  303. }
  304. jsonObj(c, configJson, nil)
  305. }
  306. // getDb downloads the database file.
  307. func (a *ServerController) getDb(c *gin.Context) {
  308. db, err := a.serverService.GetDb()
  309. if err != nil {
  310. jsonMsg(c, I18nWeb(c, "pages.index.getDatabaseError"), err)
  311. return
  312. }
  313. filename := a.serverService.BackupFilename(c.Request.Host)
  314. if !filenameRegex.MatchString(filename) {
  315. _ = c.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid filename"))
  316. return
  317. }
  318. c.Header("Content-Type", "application/octet-stream")
  319. c.Header("Content-Disposition", "attachment; filename="+filename)
  320. _, _ = c.Writer.Write(db)
  321. }
  322. // getMigration downloads a cross-engine migration file: a .dump on SQLite or a
  323. // .db SQLite database on PostgreSQL, so the data can seed the other backend.
  324. func (a *ServerController) getMigration(c *gin.Context) {
  325. data, filename, err := a.serverService.GetMigration()
  326. if err != nil {
  327. jsonMsg(c, I18nWeb(c, "pages.index.getDatabaseError"), err)
  328. return
  329. }
  330. if !filenameRegex.MatchString(filename) {
  331. _ = c.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid filename"))
  332. return
  333. }
  334. c.Header("Content-Type", "application/octet-stream")
  335. c.Header("Content-Disposition", "attachment; filename="+filename)
  336. _, _ = c.Writer.Write(data)
  337. }
  338. // importDB imports a database file and restarts the Xray service.
  339. func (a *ServerController) importDB(c *gin.Context) {
  340. file, _, err := c.Request.FormFile("db")
  341. if err != nil {
  342. jsonMsg(c, I18nWeb(c, "pages.index.readDatabaseError"), err)
  343. return
  344. }
  345. defer file.Close()
  346. // Absent field keeps this machine's own listen addresses, certificates and
  347. // node identity: the safe default for the common case of moving a config to
  348. // a new host. Send keepHostSettings=false to clone a machine wholesale.
  349. keepHostSettings := c.Request.FormValue("keepHostSettings") != "false"
  350. if err := a.serverService.ImportDB(file, keepHostSettings); err != nil {
  351. jsonMsg(c, I18nWeb(c, "pages.index.importDatabaseError"), err)
  352. return
  353. }
  354. jsonObj(c, I18nWeb(c, "pages.index.importDatabaseSuccess"), nil)
  355. }
  356. // descendants publishes read-only summaries of the nodes this panel manages so
  357. // a parent panel can surface them as transitive sub-nodes in a chained
  358. // topology. Called by the parent via the node's API token (#4983).
  359. func (a *ServerController) descendants(c *gin.Context) {
  360. data, err := (&service.NodeService{}).LocalDescendants()
  361. jsonObj(c, data, err)
  362. }
  363. // getWebCertFiles returns this panel's own web TLS certificate and key file
  364. // paths. The central panel calls it on a node (via the node's API token) so
  365. // "Set Cert from Panel" can fill a node-assigned inbound with paths that exist
  366. // on the node's filesystem instead of the central panel's — see issue #4854.
  367. func (a *ServerController) getWebCertFiles(c *gin.Context) {
  368. certFile, err := a.settingService.GetCertFile()
  369. if err != nil {
  370. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  371. return
  372. }
  373. keyFile, err := a.settingService.GetKeyFile()
  374. if err != nil {
  375. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  376. return
  377. }
  378. jsonObj(c, gin.H{"webCertFile": certFile, "webKeyFile": keyFile}, nil)
  379. }
  380. // getNewX25519Cert generates a new X25519 certificate.
  381. func (a *ServerController) getNewX25519Cert(c *gin.Context) {
  382. cert, err := a.serverService.GetNewX25519Cert()
  383. if err != nil {
  384. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.getNewX25519CertError"), err)
  385. return
  386. }
  387. jsonObj(c, cert, nil)
  388. }
  389. // getNewmldsa65 generates a new ML-DSA-65 key.
  390. func (a *ServerController) getNewmldsa65(c *gin.Context) {
  391. cert, err := a.serverService.GetNewmldsa65()
  392. if err != nil {
  393. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.getNewmldsa65Error"), err)
  394. return
  395. }
  396. jsonObj(c, cert, nil)
  397. }
  398. // getNewEchCert generates a new ECH certificate for the given SNI.
  399. func (a *ServerController) getNewEchCert(c *gin.Context) {
  400. cert, err := a.serverService.GetNewEchCert(c.PostForm("sni"))
  401. if err != nil {
  402. jsonMsg(c, "get ech certificate", err)
  403. return
  404. }
  405. jsonObj(c, cert, nil)
  406. }
  407. // getCertHash returns the hex SHA-256 of the given certificate (file path or
  408. // inline content) so the panel can fill the pinned-cert field.
  409. func (a *ServerController) getCertHash(c *gin.Context) {
  410. hashes, err := a.serverService.GetCertHash(c.PostForm("certFile"), c.PostForm("certContent"))
  411. if err != nil {
  412. jsonMsg(c, "get cert hash", err)
  413. return
  414. }
  415. jsonObj(c, hashes, nil)
  416. }
  417. // getRemoteCertHash runs `xray tls ping` against the given server and returns
  418. // its live certificate SHA-256 hash(es) for pinning.
  419. func (a *ServerController) getRemoteCertHash(c *gin.Context) {
  420. hashes, err := a.serverService.GetRemoteCertHash(c.PostForm("server"))
  421. if err != nil {
  422. jsonMsg(c, "get remote cert hash", err)
  423. return
  424. }
  425. jsonObj(c, hashes, nil)
  426. }
  427. // scanRealityTarget probes the candidate REALITY target with the given sni and
  428. // returns a feasibility verdict; allowPrivate is the panel's confirmed opt-in.
  429. func (a *ServerController) scanRealityTarget(c *gin.Context) {
  430. xver, _ := strconv.Atoi(c.PostForm("xver"))
  431. allowPrivate := c.PostForm("allowPrivate") == "true"
  432. res, err := a.serverService.ScanRealityTarget(c.PostForm("target"), c.PostForm("sni"), xver, allowPrivate)
  433. if err != nil {
  434. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.scanRealityTargetError"), err)
  435. return
  436. }
  437. jsonObj(c, res, nil)
  438. }
  439. // scanRealityTargets probes a batch of candidate REALITY targets (the supplied
  440. // comma-separated list, or the built-in seed set when empty) and returns each
  441. // verdict ranked by feasibility then latency.
  442. func (a *ServerController) scanRealityTargets(c *gin.Context) {
  443. res, err := a.serverService.ScanRealityTargets(c.PostForm("targets"))
  444. if err != nil {
  445. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.scanRealityTargetError"), err)
  446. return
  447. }
  448. jsonObj(c, res, nil)
  449. }
  450. // getNewVlessEnc generates a new VLESS encryption key.
  451. func (a *ServerController) getNewVlessEnc(c *gin.Context) {
  452. out, err := a.serverService.GetNewVlessEnc()
  453. if err != nil {
  454. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.getNewVlessEncError"), err)
  455. return
  456. }
  457. jsonObj(c, out, nil)
  458. }
  459. // getNewUUID generates a new UUID.
  460. func (a *ServerController) getNewUUID(c *gin.Context) {
  461. uuidResp, err := a.serverService.GetNewUUID()
  462. if err != nil {
  463. jsonMsg(c, "Failed to generate UUID", err)
  464. return
  465. }
  466. jsonObj(c, uuidResp, nil)
  467. }
  468. // getNewmlkem768 generates a new ML-KEM-768 key.
  469. func (a *ServerController) getNewmlkem768(c *gin.Context) {
  470. out, err := a.serverService.GetNewmlkem768()
  471. if err != nil {
  472. jsonMsg(c, "Failed to generate mlkem768 keys", err)
  473. return
  474. }
  475. jsonObj(c, out, nil)
  476. }
  477. func (a *ServerController) getClientIps(c *gin.Context) {
  478. ips, err := (&service.InboundService{}).GetAllInboundClientIps()
  479. jsonObj(c, ips, err)
  480. }
  481. func (a *ServerController) setClientIps(c *gin.Context) {
  482. var ips []model.InboundClientIps
  483. if err := c.ShouldBindJSON(&ips); err != nil {
  484. jsonMsg(c, "invalid data", err)
  485. return
  486. }
  487. err := (&service.InboundService{}).MergeInboundClientIps(ips)
  488. jsonMsg(c, "Client IPs merged", err)
  489. }