api.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. g.POST("/onlines", a.onlines)
  36. a.inboundController = NewInboundController(g)
  37. }
  38. func (a *APIController) getAllInbounds(c *gin.Context) {
  39. a.inboundController.getInbounds(c)
  40. }
  41. func (a *APIController) getSingleInbound(c *gin.Context) {
  42. a.inboundController.getInbound(c)
  43. }
  44. func (a *APIController) getClientTraffics(c *gin.Context) {
  45. a.inboundController.getClientTraffics(c)
  46. }
  47. func (a *APIController) addInbound(c *gin.Context) {
  48. a.inboundController.addInbound(c)
  49. }
  50. func (a *APIController) delInbound(c *gin.Context) {
  51. a.inboundController.delInbound(c)
  52. }
  53. func (a *APIController) updateInbound(c *gin.Context) {
  54. a.inboundController.updateInbound(c)
  55. }
  56. func (a *APIController) getClientIps(c *gin.Context) {
  57. a.inboundController.getClientIps(c)
  58. }
  59. func (a *APIController) clearClientIps(c *gin.Context) {
  60. a.inboundController.clearClientIps(c)
  61. }
  62. func (a *APIController) addInboundClient(c *gin.Context) {
  63. a.inboundController.addInboundClient(c)
  64. }
  65. func (a *APIController) delInboundClient(c *gin.Context) {
  66. a.inboundController.delInboundClient(c)
  67. }
  68. func (a *APIController) updateInboundClient(c *gin.Context) {
  69. a.inboundController.updateInboundClient(c)
  70. }
  71. func (a *APIController) resetClientTraffic(c *gin.Context) {
  72. a.inboundController.resetClientTraffic(c)
  73. }
  74. func (a *APIController) resetAllTraffics(c *gin.Context) {
  75. a.inboundController.resetAllTraffics(c)
  76. }
  77. func (a *APIController) resetAllClientTraffics(c *gin.Context) {
  78. a.inboundController.resetAllClientTraffics(c)
  79. }
  80. func (a *APIController) delDepletedClients(c *gin.Context) {
  81. a.inboundController.delDepletedClients(c)
  82. }
  83. func (a *APIController) createBackup(c *gin.Context) {
  84. a.Tgbot.SendBackupToAdmins()
  85. }
  86. func (a *APIController) onlines(c *gin.Context) {
  87. a.inboundController.onlines(c)
  88. }