Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormhsanaei <ho3ein.sanaei@gmail.com>2024-07-23 12:28:28 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2024-07-23 12:28:28 +0300
commitc7906e85980c45fd3f37d11b80e14a1075d94d4f (patch)
treeb9c20633175fc4592d8695553d78d8f18bf49d72
parente1bc43da5f1f06ea00bd28923b37b5d029522359 (diff)
API - Get client's traffic By ID
Co-Authored-By: Hassan Ali Gilani <mr.ajaxian@gmail.com>
-rw-r--r--README.md1
-rw-r--r--web/controller/api.go1
-rw-r--r--web/controller/inbound.go10
-rw-r--r--web/service/inbound.go19
4 files changed, 31 insertions, 0 deletions
diff --git a/README.md b/README.md
index e49b2277..ede2e26c 100644
--- a/README.md
+++ b/README.md
@@ -455,6 +455,7 @@ Enter the user ID in input field number 4. The Telegram accounts with this id wi
| `GET` | `"/list"` | Get all inbounds |
| `GET` | `"/get/:id"` | Get inbound with inbound.id |
| `GET` | `"/getClientTraffics/:email"` | Get Client Traffics with email |
+| `GET` | `"/getClientTrafficsById/:id"` | Get client's traffic By ID |
| `GET` | `"/createbackup"` | Telegram bot sends backup to admins |
| `POST` | `"/add"` | Add inbound |
| `POST` | `"/del/:id"` | Delete Inbound |
diff --git a/web/controller/api.go b/web/controller/api.go
index 6281097b..9944e2a3 100644
--- a/web/controller/api.go
+++ b/web/controller/api.go
@@ -33,6 +33,7 @@ func (a *APIController) initRouter(g *gin.RouterGroup) {
{"GET", "/list", a.inboundController.getInbounds},
{"GET", "/get/:id", a.inboundController.getInbound},
{"GET", "/getClientTraffics/:email", a.inboundController.getClientTraffics},
+ {"GET", "/getClientTrafficsById/:id", a.inboundController.getClientTrafficsById},
{"POST", "/add", a.inboundController.addInbound},
{"POST", "/del/:id", a.inboundController.delInbound},
{"POST", "/update/:id", a.inboundController.updateInbound},
diff --git a/web/controller/inbound.go b/web/controller/inbound.go
index cc34d1d8..c22ce192 100644
--- a/web/controller/inbound.go
+++ b/web/controller/inbound.go
@@ -77,6 +77,16 @@ func (a *InboundController) getClientTraffics(c *gin.Context) {
jsonObj(c, clientTraffics, nil)
}
+func (a *InboundController) getClientTrafficsById(c *gin.Context) {
+ id := c.Param("id")
+ clientTraffics, err := a.inboundService.GetClientTrafficByID(id)
+ if err != nil {
+ jsonMsg(c, "Error getting traffics", err)
+ return
+ }
+ jsonObj(c, clientTraffics, nil)
+}
+
func (a *InboundController) addInbound(c *gin.Context) {
inbound := &model.Inbound{}
err := c.ShouldBind(inbound)
diff --git a/web/service/inbound.go b/web/service/inbound.go
index 6f9aac98..25a43f47 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -1750,6 +1750,25 @@ func (s *InboundService) GetClientTrafficByEmail(email string) (traffic *xray.Cl
return nil, nil
}
+func (s *InboundService) GetClientTrafficByID(id string) ([]xray.ClientTraffic, error) {
+ db := database.GetDB()
+ var traffics []xray.ClientTraffic
+
+ err := db.Model(xray.ClientTraffic{}).Where(`email IN(
+ SELECT JSON_EXTRACT(client.value, '$.email') as email
+ FROM inbounds,
+ JSON_EACH(JSON_EXTRACT(inbounds.settings, '$.clients')) AS client
+ WHERE
+ JSON_EXTRACT(client.value, '$.id') in (?)
+ )`, id).Find(&traffics).Error
+
+ if err != nil {
+ logger.Debug(err)
+ return nil, err
+ }
+ return traffics, err
+}
+
func (s *InboundService) SearchClientTraffic(query string) (traffic *xray.ClientTraffic, err error) {
db := database.GetDB()
inbound := &model.Inbound{}