3x-ui/web/controller/api.go

107 lines
2.8 KiB
Go
Raw Normal View History

2023-02-09 22:18:06 +03:00
package controller
2023-05-19 00:01:05 +03:00
import (
"x-ui/web/service"
"github.com/gin-gonic/gin"
)
2023-02-09 22:18:06 +03:00
2023-04-02 01:00:15 +03:00
type APIController struct {
BaseController
inboundController *InboundController
2023-05-19 00:01:05 +03:00
Tgbot service.Tgbot
2023-02-09 22:18:06 +03:00
}
func NewAPIController(g *gin.RouterGroup) *APIController {
a := &APIController{}
a.initRouter(g)
return a
2023-02-09 22:18:06 +03:00
}
func (a *APIController) initRouter(g *gin.RouterGroup) {
g = g.Group("/panel/api/inbounds")
g.Use(a.checkLogin)
2023-04-10 20:03:19 +03:00
g.GET("/list", a.getAllInbounds)
g.GET("/get/:id", a.getSingleInbound)
g.GET("/getClientTraffics/:email", a.getClientTraffics)
g.POST("/add", a.addInbound)
g.POST("/del/:id", a.delInbound)
g.POST("/update/:id", a.updateInbound)
g.POST("/clientIps/:email", a.getClientIps)
g.POST("/clearClientIps/:email", a.clearClientIps)
g.POST("/addClient", a.addInboundClient)
g.POST("/:id/delClient/:clientId", a.delInboundClient)
g.POST("/updateClient/:clientId", a.updateInboundClient)
g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
g.POST("/resetAllTraffics", a.resetAllTraffics)
g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics)
g.POST("/delDepletedClients/:id", a.delDepletedClients)
2023-05-19 00:01:05 +03:00
g.GET("/createbackup", a.createBackup)
a.inboundController = NewInboundController(g)
2023-02-09 22:18:06 +03:00
}
2023-04-02 01:00:15 +03:00
func (a *APIController) getAllInbounds(c *gin.Context) {
a.inboundController.getInbounds(c)
2023-02-09 22:18:06 +03:00
}
2023-04-02 01:00:15 +03:00
func (a *APIController) getSingleInbound(c *gin.Context) {
a.inboundController.getInbound(c)
2023-02-09 22:18:06 +03:00
}
func (a *APIController) getClientTraffics(c *gin.Context) {
a.inboundController.getClientTraffics(c)
}
2023-02-09 22:18:06 +03:00
func (a *APIController) addInbound(c *gin.Context) {
a.inboundController.addInbound(c)
2023-02-09 22:18:06 +03:00
}
2023-02-09 22:18:06 +03:00
func (a *APIController) delInbound(c *gin.Context) {
a.inboundController.delInbound(c)
2023-02-09 22:18:06 +03:00
}
2023-02-09 22:18:06 +03:00
func (a *APIController) updateInbound(c *gin.Context) {
a.inboundController.updateInbound(c)
2023-04-02 01:00:15 +03:00
}
func (a *APIController) getClientIps(c *gin.Context) {
a.inboundController.getClientIps(c)
2023-04-02 01:00:15 +03:00
}
func (a *APIController) clearClientIps(c *gin.Context) {
a.inboundController.clearClientIps(c)
2023-04-02 01:00:15 +03:00
}
2023-04-02 01:00:15 +03:00
func (a *APIController) addInboundClient(c *gin.Context) {
a.inboundController.addInboundClient(c)
2023-04-02 01:00:15 +03:00
}
2023-04-02 01:00:15 +03:00
func (a *APIController) delInboundClient(c *gin.Context) {
a.inboundController.delInboundClient(c)
2023-04-02 01:00:15 +03:00
}
2023-04-02 01:00:15 +03:00
func (a *APIController) updateInboundClient(c *gin.Context) {
a.inboundController.updateInboundClient(c)
2023-04-02 01:00:15 +03:00
}
2023-04-02 01:00:15 +03:00
func (a *APIController) resetClientTraffic(c *gin.Context) {
a.inboundController.resetClientTraffic(c)
}
func (a *APIController) resetAllTraffics(c *gin.Context) {
a.inboundController.resetAllTraffics(c)
}
func (a *APIController) resetAllClientTraffics(c *gin.Context) {
a.inboundController.resetAllClientTraffics(c)
2023-02-09 22:18:06 +03:00
}
func (a *APIController) delDepletedClients(c *gin.Context) {
a.inboundController.delDepletedClients(c)
}
2023-05-19 00:01:05 +03:00
func (a *APIController) createBackup(c *gin.Context) {
2023-05-21 01:59:27 +03:00
a.Tgbot.SendBackupToAdmins()
2023-05-19 00:01:05 +03:00
}