1
0

api.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package controller
  2. import (
  3. "x-ui/web/service"
  4. "github.com/gin-gonic/gin"
  5. )
  6. type APIController struct {
  7. BaseController
  8. inboundController *InboundController
  9. Tgbot service.Tgbot
  10. }
  11. func NewAPIController(g *gin.RouterGroup) *APIController {
  12. a := &APIController{}
  13. a.initRouter(g)
  14. return a
  15. }
  16. func (a *APIController) initRouter(g *gin.RouterGroup) {
  17. g = g.Group("/panel/api/inbounds")
  18. g.Use(a.checkLogin)
  19. g.GET("/list", a.getAllInbounds)
  20. g.GET("/get/:id", a.getSingleInbound)
  21. g.GET("/getClientTraffics/:email", a.getClientTraffics)
  22. g.POST("/add", a.addInbound)
  23. g.POST("/del/:id", a.delInbound)
  24. g.POST("/update/:id", a.updateInbound)
  25. g.POST("/clientIps/:email", a.getClientIps)
  26. g.POST("/clearClientIps/:email", a.clearClientIps)
  27. g.POST("/addClient", a.addInboundClient)
  28. g.POST("/:id/delClient/:clientId", a.delInboundClient)
  29. g.POST("/updateClient/:clientId", a.updateInboundClient)
  30. g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
  31. g.POST("/resetAllTraffics", a.resetAllTraffics)
  32. g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics)
  33. g.POST("/delDepletedClients/:id", a.delDepletedClients)
  34. g.GET("/createbackup", a.createBackup)
  35. a.inboundController = NewInboundController(g)
  36. }
  37. func (a *APIController) getAllInbounds(c *gin.Context) {
  38. a.inboundController.getInbounds(c)
  39. }
  40. func (a *APIController) getSingleInbound(c *gin.Context) {
  41. a.inboundController.getInbound(c)
  42. }
  43. func (a *APIController) getClientTraffics(c *gin.Context) {
  44. a.inboundController.getClientTraffics(c)
  45. }
  46. func (a *APIController) addInbound(c *gin.Context) {
  47. a.inboundController.addInbound(c)
  48. }
  49. func (a *APIController) delInbound(c *gin.Context) {
  50. a.inboundController.delInbound(c)
  51. }
  52. func (a *APIController) updateInbound(c *gin.Context) {
  53. a.inboundController.updateInbound(c)
  54. }
  55. func (a *APIController) getClientIps(c *gin.Context) {
  56. a.inboundController.getClientIps(c)
  57. }
  58. func (a *APIController) clearClientIps(c *gin.Context) {
  59. a.inboundController.clearClientIps(c)
  60. }
  61. func (a *APIController) addInboundClient(c *gin.Context) {
  62. a.inboundController.addInboundClient(c)
  63. }
  64. func (a *APIController) delInboundClient(c *gin.Context) {
  65. a.inboundController.delInboundClient(c)
  66. }
  67. func (a *APIController) updateInboundClient(c *gin.Context) {
  68. a.inboundController.updateInboundClient(c)
  69. }
  70. func (a *APIController) resetClientTraffic(c *gin.Context) {
  71. a.inboundController.resetClientTraffic(c)
  72. }
  73. func (a *APIController) resetAllTraffics(c *gin.Context) {
  74. a.inboundController.resetAllTraffics(c)
  75. }
  76. func (a *APIController) resetAllClientTraffics(c *gin.Context) {
  77. a.inboundController.resetAllClientTraffics(c)
  78. }
  79. func (a *APIController) delDepletedClients(c *gin.Context) {
  80. a.inboundController.delDepletedClients(c)
  81. }
  82. func (a *APIController) createBackup(c *gin.Context) {
  83. a.Tgbot.SendBackupToAdmins()
  84. }