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