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 {
|
2023-04-09 22:43:18 +03:00
|
|
|
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 {
|
2023-04-09 22:43:18 +03:00
|
|
|
a := &APIController{}
|
|
|
|
a.initRouter(g)
|
|
|
|
return a
|
2023-02-09 22:18:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *APIController) initRouter(g *gin.RouterGroup) {
|
2023-05-14 00:11:18 +03:00
|
|
|
g = g.Group("/panel/api/inbounds")
|
2023-04-09 22:43:18 +03:00
|
|
|
g.Use(a.checkLogin)
|
|
|
|
|
2023-04-10 20:03:19 +03:00
|
|
|
g.GET("/list", a.getAllInbounds)
|
2023-04-09 22:43:18 +03:00
|
|
|
g.GET("/get/:id", a.getSingleInbound)
|
2023-04-21 18:36:59 +03:00
|
|
|
g.GET("/getClientTraffics/:email", a.getClientTraffics)
|
2023-04-09 22:43:18 +03:00
|
|
|
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)
|
2023-04-25 18:16:09 +03:00
|
|
|
g.POST("/addClient", a.addInboundClient)
|
2023-04-24 14:37:11 +03:00
|
|
|
g.POST("/:id/delClient/:clientId", a.delInboundClient)
|
2023-04-25 14:08:35 +03:00
|
|
|
g.POST("/updateClient/:clientId", a.updateInboundClient)
|
2023-04-09 22:43:18 +03:00
|
|
|
g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
|
|
|
|
g.POST("/resetAllTraffics", a.resetAllTraffics)
|
|
|
|
g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics)
|
2023-04-25 18:16:09 +03:00
|
|
|
g.POST("/delDepletedClients/:id", a.delDepletedClients)
|
2023-05-19 00:01:05 +03:00
|
|
|
g.GET("/createbackup", a.createBackup)
|
2023-12-05 00:00:47 +03:00
|
|
|
g.POST("/onlines", a.onlines)
|
|
|
|
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController = NewInboundController(g)
|
2023-02-09 22:18:06 +03:00
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-04-02 01:00:15 +03:00
|
|
|
func (a *APIController) getAllInbounds(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.getInbounds(c)
|
2023-02-09 22:18:06 +03:00
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-04-02 01:00:15 +03:00
|
|
|
func (a *APIController) getSingleInbound(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.getInbound(c)
|
2023-02-09 22:18:06 +03:00
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-04-21 18:36:59 +03:00
|
|
|
func (a *APIController) getClientTraffics(c *gin.Context) {
|
|
|
|
a.inboundController.getClientTraffics(c)
|
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-02-09 22:18:06 +03:00
|
|
|
func (a *APIController) addInbound(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.addInbound(c)
|
2023-02-09 22:18:06 +03:00
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-02-09 22:18:06 +03:00
|
|
|
func (a *APIController) delInbound(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.delInbound(c)
|
2023-02-09 22:18:06 +03:00
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-02-09 22:18:06 +03:00
|
|
|
func (a *APIController) updateInbound(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.updateInbound(c)
|
2023-04-02 01:00:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *APIController) getClientIps(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.getClientIps(c)
|
2023-04-02 01:00:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *APIController) clearClientIps(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.clearClientIps(c)
|
2023-04-02 01:00:15 +03:00
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-04-02 01:00:15 +03:00
|
|
|
func (a *APIController) addInboundClient(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.addInboundClient(c)
|
2023-04-02 01:00:15 +03:00
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-04-02 01:00:15 +03:00
|
|
|
func (a *APIController) delInboundClient(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.delInboundClient(c)
|
2023-04-02 01:00:15 +03:00
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-04-02 01:00:15 +03:00
|
|
|
func (a *APIController) updateInboundClient(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.updateInboundClient(c)
|
2023-04-02 01:00:15 +03:00
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-04-02 01:00:15 +03:00
|
|
|
func (a *APIController) resetClientTraffic(c *gin.Context) {
|
2023-04-09 22:43:18 +03:00
|
|
|
a.inboundController.resetClientTraffic(c)
|
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-04-09 22:43:18 +03:00
|
|
|
func (a *APIController) resetAllTraffics(c *gin.Context) {
|
|
|
|
a.inboundController.resetAllTraffics(c)
|
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-04-09 22:43:18 +03:00
|
|
|
func (a *APIController) resetAllClientTraffics(c *gin.Context) {
|
|
|
|
a.inboundController.resetAllClientTraffics(c)
|
2023-02-09 22:18:06 +03:00
|
|
|
}
|
2023-05-14 00:11:18 +03:00
|
|
|
|
2023-04-25 18:16:09 +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
|
|
|
}
|
2023-12-05 00:00:47 +03:00
|
|
|
|
|
|
|
func (a *APIController) onlines(c *gin.Context) {
|
|
|
|
a.inboundController.onlines(c)
|
|
|
|
}
|