inbound.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. package controller
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "github.com/mhsanaei/3x-ui/v3/database/model"
  8. "github.com/mhsanaei/3x-ui/v3/web/service"
  9. "github.com/mhsanaei/3x-ui/v3/web/session"
  10. "github.com/mhsanaei/3x-ui/v3/web/websocket"
  11. "github.com/gin-gonic/gin"
  12. )
  13. // InboundController handles HTTP requests related to Xray inbounds management.
  14. type InboundController struct {
  15. inboundService service.InboundService
  16. xrayService service.XrayService
  17. }
  18. // NewInboundController creates a new InboundController and sets up its routes.
  19. func NewInboundController(g *gin.RouterGroup) *InboundController {
  20. a := &InboundController{}
  21. a.initRouter(g)
  22. return a
  23. }
  24. // broadcastInboundsUpdateClientLimit is the threshold past which we skip the
  25. // full-list push over WebSocket and signal the frontend to re-fetch via REST.
  26. // Mirrors the same heuristic used by the periodic traffic job.
  27. const broadcastInboundsUpdateClientLimit = 5000
  28. // broadcastInboundsUpdate fetches and broadcasts the inbound list for userId.
  29. // At scale (10k+ clients) the marshaled JSON exceeds the WS payload ceiling,
  30. // so we send an invalidate signal instead — frontend re-fetches via REST.
  31. // Skipped entirely when no WebSocket clients are connected.
  32. func (a *InboundController) broadcastInboundsUpdate(userId int) {
  33. if !websocket.HasClients() {
  34. return
  35. }
  36. inbounds, err := a.inboundService.GetInbounds(userId)
  37. if err != nil {
  38. return
  39. }
  40. totalClients := 0
  41. for _, ib := range inbounds {
  42. totalClients += len(ib.ClientStats)
  43. }
  44. if totalClients > broadcastInboundsUpdateClientLimit {
  45. websocket.BroadcastInvalidate(websocket.MessageTypeInbounds)
  46. return
  47. }
  48. websocket.BroadcastInbounds(inbounds)
  49. }
  50. // initRouter initializes the routes for inbound-related operations.
  51. func (a *InboundController) initRouter(g *gin.RouterGroup) {
  52. g.GET("/list", a.getInbounds)
  53. g.GET("/get/:id", a.getInbound)
  54. g.GET("/getClientTraffics/:email", a.getClientTraffics)
  55. g.GET("/getClientTrafficsById/:id", a.getClientTrafficsById)
  56. g.POST("/add", a.addInbound)
  57. g.POST("/del/:id", a.delInbound)
  58. g.POST("/update/:id", a.updateInbound)
  59. g.POST("/setEnable/:id", a.setInboundEnable)
  60. g.POST("/clientIps/:email", a.getClientIps)
  61. g.POST("/clearClientIps/:email", a.clearClientIps)
  62. g.POST("/addClient", a.addInboundClient)
  63. g.POST("/:id/copyClients", a.copyInboundClients)
  64. g.POST("/:id/delClient/:clientId", a.delInboundClient)
  65. g.POST("/updateClient/:clientId", a.updateInboundClient)
  66. g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
  67. g.POST("/resetAllTraffics", a.resetAllTraffics)
  68. g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics)
  69. g.POST("/delDepletedClients/:id", a.delDepletedClients)
  70. g.POST("/import", a.importInbound)
  71. g.POST("/onlines", a.onlines)
  72. g.POST("/lastOnline", a.lastOnline)
  73. g.POST("/updateClientTraffic/:email", a.updateClientTraffic)
  74. g.POST("/:id/delClientByEmail/:email", a.delInboundClientByEmail)
  75. }
  76. type CopyInboundClientsRequest struct {
  77. SourceInboundID int `form:"sourceInboundId" json:"sourceInboundId"`
  78. ClientEmails []string `form:"clientEmails" json:"clientEmails"`
  79. Flow string `form:"flow" json:"flow"`
  80. }
  81. // getInbounds retrieves the list of inbounds for the logged-in user.
  82. func (a *InboundController) getInbounds(c *gin.Context) {
  83. user := session.GetLoginUser(c)
  84. inbounds, err := a.inboundService.GetInbounds(user.Id)
  85. if err != nil {
  86. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.obtain"), err)
  87. return
  88. }
  89. jsonObj(c, inbounds, nil)
  90. }
  91. // getInbound retrieves a specific inbound by its ID.
  92. func (a *InboundController) getInbound(c *gin.Context) {
  93. id, err := strconv.Atoi(c.Param("id"))
  94. if err != nil {
  95. jsonMsg(c, I18nWeb(c, "get"), err)
  96. return
  97. }
  98. inbound, err := a.inboundService.GetInbound(id)
  99. if err != nil {
  100. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.obtain"), err)
  101. return
  102. }
  103. jsonObj(c, inbound, nil)
  104. }
  105. // getClientTraffics retrieves client traffic information by email.
  106. func (a *InboundController) getClientTraffics(c *gin.Context) {
  107. email := c.Param("email")
  108. clientTraffics, err := a.inboundService.GetClientTrafficByEmail(email)
  109. if err != nil {
  110. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.trafficGetError"), err)
  111. return
  112. }
  113. jsonObj(c, clientTraffics, nil)
  114. }
  115. // getClientTrafficsById retrieves client traffic information by inbound ID.
  116. func (a *InboundController) getClientTrafficsById(c *gin.Context) {
  117. id := c.Param("id")
  118. clientTraffics, err := a.inboundService.GetClientTrafficByID(id)
  119. if err != nil {
  120. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.trafficGetError"), err)
  121. return
  122. }
  123. jsonObj(c, clientTraffics, nil)
  124. }
  125. // addInbound creates a new inbound configuration.
  126. func (a *InboundController) addInbound(c *gin.Context) {
  127. inbound := &model.Inbound{}
  128. err := c.ShouldBind(inbound)
  129. if err != nil {
  130. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundCreateSuccess"), err)
  131. return
  132. }
  133. user := session.GetLoginUser(c)
  134. inbound.UserId = user.Id
  135. // Treat NodeID=0 as "no node" — gin's *int form binding can land on
  136. // 0 when the field is absent or empty, and 0 is never a valid Node
  137. // row id. Without this normalization the runtime layer would try to
  138. // load Node id=0 and surface "record not found".
  139. if inbound.NodeID != nil && *inbound.NodeID == 0 {
  140. inbound.NodeID = nil
  141. }
  142. // When the central panel deploys an inbound to a remote node, it sends
  143. // the Tag pre-computed (so both DBs agree on the identifier). Local
  144. // UI submits don't include a Tag — we compute one from listen+port
  145. // using the original collision-avoiding scheme.
  146. if inbound.Tag == "" {
  147. if inbound.Listen == "" || inbound.Listen == "0.0.0.0" || inbound.Listen == "::" || inbound.Listen == "::0" {
  148. inbound.Tag = fmt.Sprintf("inbound-%v", inbound.Port)
  149. } else {
  150. inbound.Tag = fmt.Sprintf("inbound-%v:%v", inbound.Listen, inbound.Port)
  151. }
  152. }
  153. inbound, needRestart, err := a.inboundService.AddInbound(inbound)
  154. if err != nil {
  155. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  156. return
  157. }
  158. jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundCreateSuccess"), inbound, nil)
  159. if needRestart {
  160. a.xrayService.SetToNeedRestart()
  161. }
  162. a.broadcastInboundsUpdate(user.Id)
  163. }
  164. // delInbound deletes an inbound configuration by its ID.
  165. func (a *InboundController) delInbound(c *gin.Context) {
  166. id, err := strconv.Atoi(c.Param("id"))
  167. if err != nil {
  168. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundDeleteSuccess"), err)
  169. return
  170. }
  171. needRestart, err := a.inboundService.DelInbound(id)
  172. if err != nil {
  173. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  174. return
  175. }
  176. jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundDeleteSuccess"), id, nil)
  177. if needRestart {
  178. a.xrayService.SetToNeedRestart()
  179. }
  180. user := session.GetLoginUser(c)
  181. a.broadcastInboundsUpdate(user.Id)
  182. }
  183. // updateInbound updates an existing inbound configuration.
  184. func (a *InboundController) updateInbound(c *gin.Context) {
  185. id, err := strconv.Atoi(c.Param("id"))
  186. if err != nil {
  187. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
  188. return
  189. }
  190. inbound := &model.Inbound{
  191. Id: id,
  192. }
  193. err = c.ShouldBind(inbound)
  194. if err != nil {
  195. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
  196. return
  197. }
  198. // Same NodeID=0 → nil normalisation as addInbound. UpdateInbound
  199. // loads the existing row's NodeID from DB anyway (Phase 1 doesn't
  200. // support migrating an inbound between nodes), but normalising here
  201. // keeps the wire shape consistent.
  202. if inbound.NodeID != nil && *inbound.NodeID == 0 {
  203. inbound.NodeID = nil
  204. }
  205. inbound, needRestart, err := a.inboundService.UpdateInbound(inbound)
  206. if err != nil {
  207. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  208. return
  209. }
  210. jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), inbound, nil)
  211. if needRestart {
  212. a.xrayService.SetToNeedRestart()
  213. }
  214. user := session.GetLoginUser(c)
  215. a.broadcastInboundsUpdate(user.Id)
  216. }
  217. // setInboundEnable flips only the enable flag of an inbound. This is a
  218. // dedicated endpoint because the regular update path serialises the entire
  219. // settings JSON (every client) — far too heavy for an interactive switch
  220. // on inbounds with thousands of clients. Frontend optimistically updates
  221. // the UI; we just persist + sync xray + nudge other open admin sessions.
  222. func (a *InboundController) setInboundEnable(c *gin.Context) {
  223. id, err := strconv.Atoi(c.Param("id"))
  224. if err != nil {
  225. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
  226. return
  227. }
  228. type form struct {
  229. Enable bool `json:"enable" form:"enable"`
  230. }
  231. var f form
  232. if err := c.ShouldBind(&f); err != nil {
  233. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  234. return
  235. }
  236. needRestart, err := a.inboundService.SetInboundEnable(id, f.Enable)
  237. if err != nil {
  238. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  239. return
  240. }
  241. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), nil)
  242. if needRestart {
  243. a.xrayService.SetToNeedRestart()
  244. }
  245. // Cross-admin sync: lightweight invalidate signal (a few hundred bytes)
  246. // instead of fetching + serialising the whole inbound list. Other open
  247. // sessions re-fetch via REST. The toggling admin's own UI already
  248. // updated optimistically.
  249. websocket.BroadcastInvalidate(websocket.MessageTypeInbounds)
  250. }
  251. // getClientIps retrieves the IP addresses associated with a client by email.
  252. func (a *InboundController) getClientIps(c *gin.Context) {
  253. email := c.Param("email")
  254. ips, err := a.inboundService.GetInboundClientIps(email)
  255. if err != nil || ips == "" {
  256. jsonObj(c, "No IP Record", nil)
  257. return
  258. }
  259. // Prefer returning a normalized string list for consistent UI rendering
  260. type ipWithTimestamp struct {
  261. IP string `json:"ip"`
  262. Timestamp int64 `json:"timestamp"`
  263. }
  264. var ipsWithTime []ipWithTimestamp
  265. if err := json.Unmarshal([]byte(ips), &ipsWithTime); err == nil && len(ipsWithTime) > 0 {
  266. formatted := make([]string, 0, len(ipsWithTime))
  267. for _, item := range ipsWithTime {
  268. if item.IP == "" {
  269. continue
  270. }
  271. if item.Timestamp > 0 {
  272. ts := time.Unix(item.Timestamp, 0).Local().Format("2006-01-02 15:04:05")
  273. formatted = append(formatted, fmt.Sprintf("%s (%s)", item.IP, ts))
  274. continue
  275. }
  276. formatted = append(formatted, item.IP)
  277. }
  278. jsonObj(c, formatted, nil)
  279. return
  280. }
  281. var oldIps []string
  282. if err := json.Unmarshal([]byte(ips), &oldIps); err == nil && len(oldIps) > 0 {
  283. jsonObj(c, oldIps, nil)
  284. return
  285. }
  286. // If parsing fails, return as string
  287. jsonObj(c, ips, nil)
  288. }
  289. // clearClientIps clears the IP addresses for a client by email.
  290. func (a *InboundController) clearClientIps(c *gin.Context) {
  291. email := c.Param("email")
  292. err := a.inboundService.ClearClientIps(email)
  293. if err != nil {
  294. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.updateSuccess"), err)
  295. return
  296. }
  297. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.logCleanSuccess"), nil)
  298. }
  299. // addInboundClient adds a new client to an existing inbound.
  300. func (a *InboundController) addInboundClient(c *gin.Context) {
  301. data := &model.Inbound{}
  302. err := c.ShouldBind(data)
  303. if err != nil {
  304. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
  305. return
  306. }
  307. needRestart, err := a.inboundService.AddInboundClient(data)
  308. if err != nil {
  309. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  310. return
  311. }
  312. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundClientAddSuccess"), nil)
  313. if needRestart {
  314. a.xrayService.SetToNeedRestart()
  315. }
  316. }
  317. // copyInboundClients copies clients from source inbound to target inbound.
  318. func (a *InboundController) copyInboundClients(c *gin.Context) {
  319. targetID, err := strconv.Atoi(c.Param("id"))
  320. if err != nil {
  321. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  322. return
  323. }
  324. req := &CopyInboundClientsRequest{}
  325. err = c.ShouldBind(req)
  326. if err != nil {
  327. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  328. return
  329. }
  330. if req.SourceInboundID <= 0 {
  331. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), fmt.Errorf("invalid source inbound id"))
  332. return
  333. }
  334. result, needRestart, err := a.inboundService.CopyInboundClients(targetID, req.SourceInboundID, req.ClientEmails, req.Flow)
  335. if err != nil {
  336. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  337. return
  338. }
  339. jsonObj(c, result, nil)
  340. if needRestart {
  341. a.xrayService.SetToNeedRestart()
  342. }
  343. }
  344. // delInboundClient deletes a client from an inbound by inbound ID and client ID.
  345. func (a *InboundController) delInboundClient(c *gin.Context) {
  346. id, err := strconv.Atoi(c.Param("id"))
  347. if err != nil {
  348. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
  349. return
  350. }
  351. clientId := c.Param("clientId")
  352. needRestart, err := a.inboundService.DelInboundClient(id, clientId)
  353. if err != nil {
  354. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  355. return
  356. }
  357. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundClientDeleteSuccess"), nil)
  358. if needRestart {
  359. a.xrayService.SetToNeedRestart()
  360. }
  361. }
  362. // updateInboundClient updates a client's configuration in an inbound.
  363. func (a *InboundController) updateInboundClient(c *gin.Context) {
  364. clientId := c.Param("clientId")
  365. inbound := &model.Inbound{}
  366. err := c.ShouldBind(inbound)
  367. if err != nil {
  368. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
  369. return
  370. }
  371. needRestart, err := a.inboundService.UpdateInboundClient(inbound, clientId)
  372. if err != nil {
  373. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  374. return
  375. }
  376. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundClientUpdateSuccess"), nil)
  377. if needRestart {
  378. a.xrayService.SetToNeedRestart()
  379. }
  380. }
  381. // resetClientTraffic resets the traffic counter for a specific client in an inbound.
  382. func (a *InboundController) resetClientTraffic(c *gin.Context) {
  383. id, err := strconv.Atoi(c.Param("id"))
  384. if err != nil {
  385. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
  386. return
  387. }
  388. email := c.Param("email")
  389. needRestart, err := a.inboundService.ResetClientTraffic(id, email)
  390. if err != nil {
  391. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  392. return
  393. }
  394. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetInboundClientTrafficSuccess"), nil)
  395. if needRestart {
  396. a.xrayService.SetToNeedRestart()
  397. }
  398. }
  399. // resetAllTraffics resets all traffic counters across all inbounds.
  400. func (a *InboundController) resetAllTraffics(c *gin.Context) {
  401. err := a.inboundService.ResetAllTraffics()
  402. if err != nil {
  403. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  404. return
  405. } else {
  406. a.xrayService.SetToNeedRestart()
  407. }
  408. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetAllTrafficSuccess"), nil)
  409. }
  410. // resetAllClientTraffics resets traffic counters for all clients in a specific inbound.
  411. func (a *InboundController) resetAllClientTraffics(c *gin.Context) {
  412. id, err := strconv.Atoi(c.Param("id"))
  413. if err != nil {
  414. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
  415. return
  416. }
  417. err = a.inboundService.ResetAllClientTraffics(id)
  418. if err != nil {
  419. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  420. return
  421. } else {
  422. a.xrayService.SetToNeedRestart()
  423. }
  424. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetAllClientTrafficSuccess"), nil)
  425. }
  426. // importInbound imports an inbound configuration from provided data.
  427. func (a *InboundController) importInbound(c *gin.Context) {
  428. inbound := &model.Inbound{}
  429. err := json.Unmarshal([]byte(c.PostForm("data")), inbound)
  430. if err != nil {
  431. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  432. return
  433. }
  434. user := session.GetLoginUser(c)
  435. inbound.Id = 0
  436. inbound.UserId = user.Id
  437. if inbound.Tag == "" {
  438. if inbound.Listen == "" || inbound.Listen == "0.0.0.0" || inbound.Listen == "::" || inbound.Listen == "::0" {
  439. inbound.Tag = fmt.Sprintf("inbound-%v", inbound.Port)
  440. } else {
  441. inbound.Tag = fmt.Sprintf("inbound-%v:%v", inbound.Listen, inbound.Port)
  442. }
  443. }
  444. for index := range inbound.ClientStats {
  445. inbound.ClientStats[index].Id = 0
  446. inbound.ClientStats[index].Enable = true
  447. }
  448. needRestart := false
  449. inbound, needRestart, err = a.inboundService.AddInbound(inbound)
  450. jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundCreateSuccess"), inbound, err)
  451. if err == nil && needRestart {
  452. a.xrayService.SetToNeedRestart()
  453. }
  454. }
  455. // delDepletedClients deletes clients in an inbound who have exhausted their traffic limits.
  456. func (a *InboundController) delDepletedClients(c *gin.Context) {
  457. id, err := strconv.Atoi(c.Param("id"))
  458. if err != nil {
  459. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
  460. return
  461. }
  462. err = a.inboundService.DelDepletedClients(id)
  463. if err != nil {
  464. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  465. return
  466. }
  467. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.delDepletedClientsSuccess"), nil)
  468. }
  469. // onlines retrieves the list of currently online clients.
  470. func (a *InboundController) onlines(c *gin.Context) {
  471. jsonObj(c, a.inboundService.GetOnlineClients(), nil)
  472. }
  473. // lastOnline retrieves the last online timestamps for clients.
  474. func (a *InboundController) lastOnline(c *gin.Context) {
  475. data, err := a.inboundService.GetClientsLastOnline()
  476. jsonObj(c, data, err)
  477. }
  478. // updateClientTraffic updates the traffic statistics for a client by email.
  479. func (a *InboundController) updateClientTraffic(c *gin.Context) {
  480. email := c.Param("email")
  481. // Define the request structure for traffic update
  482. type TrafficUpdateRequest struct {
  483. Upload int64 `json:"upload"`
  484. Download int64 `json:"download"`
  485. }
  486. var request TrafficUpdateRequest
  487. err := c.ShouldBindJSON(&request)
  488. if err != nil {
  489. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
  490. return
  491. }
  492. err = a.inboundService.UpdateClientTrafficByEmail(email, request.Upload, request.Download)
  493. if err != nil {
  494. jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
  495. return
  496. }
  497. jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundClientUpdateSuccess"), nil)
  498. }
  499. // delInboundClientByEmail deletes a client from an inbound by email address.
  500. func (a *InboundController) delInboundClientByEmail(c *gin.Context) {
  501. inboundId, err := strconv.Atoi(c.Param("id"))
  502. if err != nil {
  503. jsonMsg(c, "Invalid inbound ID", err)
  504. return
  505. }
  506. email := c.Param("email")
  507. needRestart, err := a.inboundService.DelInboundClientByEmail(inboundId, email)
  508. if err != nil {
  509. jsonMsg(c, "Failed to delete client by email", err)
  510. return
  511. }
  512. jsonMsg(c, "Client deleted successfully", nil)
  513. if needRestart {
  514. a.xrayService.SetToNeedRestart()
  515. }
  516. }