mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
- Added REST api
- Added route for get server status
This commit is contained in:
parent
195effd177
commit
14137af453
7 changed files with 752 additions and 25 deletions
137
docs/API.cn.md
Normal file
137
docs/API.cn.md
Normal file
|
@ -0,0 +1,137 @@
|
|||
# API 文档
|
||||
|
||||
## Inbounds
|
||||
|
||||
### 获取所有 Inbounds
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/inbounds/`
|
||||
- **描述**: 获取所有 inbounds 的列表。
|
||||
|
||||
### 重置所有客户流量
|
||||
- **方法**: `DELETE`
|
||||
- **端点**: `/inbounds/traffic`
|
||||
- **描述**: 重置所有客户的流量。
|
||||
|
||||
---
|
||||
|
||||
## Inbound
|
||||
|
||||
### 添加 Inbound
|
||||
- **方法**: `POST`
|
||||
- **端点**: `/inbounds/`
|
||||
- **描述**: 添加新的 inbound。
|
||||
|
||||
### 通过 ID 获取 Inbound
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/inbounds/:id`
|
||||
- **描述**: 通过 ID 获取特定 inbound 的信息。
|
||||
|
||||
### 通过 ID 删除 Inbound
|
||||
- **方法**: `DELETE`
|
||||
- **端点**: `/inbounds/:id`
|
||||
- **描述**: 通过 ID 删除 inbound。
|
||||
|
||||
### 通过 ID 更新 Inbound
|
||||
- **方法**: `PUT`
|
||||
- **端点**: `/inbounds/:id`
|
||||
- **描述**: 通过 ID 更新 inbound 的信息。
|
||||
|
||||
### 删除 Inbound 流量
|
||||
- **方法**: `DELETE`
|
||||
- **端点**: `/inbounds/:id/traffic`
|
||||
- **描述**: 通过 ID 删除 inbound 流量。
|
||||
|
||||
### 删除流量耗尽的客户
|
||||
- **方法**: `DELETE`
|
||||
- **端点**: `/inbounds/:id/depleted-clients`
|
||||
- **描述**: 删除特定 inbound 下流量已耗尽的客户。
|
||||
|
||||
---
|
||||
|
||||
## Inbound 客户
|
||||
|
||||
### 获取 Inbound 客户
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/inbounds/:id/clients/`
|
||||
- **描述**: 获取特定 inbound 的客户列表。
|
||||
|
||||
---
|
||||
|
||||
## Inbound 客户管理
|
||||
|
||||
### 添加 Inbound 客户
|
||||
- **方法**: `POST`
|
||||
- **端点**: `/inbounds/:id/clients`
|
||||
- **描述**: 向 inbound 添加新的客户。
|
||||
|
||||
### 通过 ID 获取客户
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/inbounds/:id/clients/:clientId`
|
||||
- **描述**: 通过 ID 获取客户信息。
|
||||
|
||||
### 更新 Inbound 客户
|
||||
- **方法**: `PUT`
|
||||
- **端点**: `/inbounds/:id/clients/:clientId`
|
||||
- **描述**: 通过 ID 更新客户信息。
|
||||
|
||||
### 删除 Inbound 客户
|
||||
- **方法**: `DELETE`
|
||||
- **端点**: `/inbounds/:id/clients/:clientId`
|
||||
- **描述**: 通过 ID 删除客户。
|
||||
|
||||
### 通过 ID 获取客户流量
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/inbounds/:id/clients/:clientId/traffic`
|
||||
- **描述**: 通过 ID 获取客户流量统计信息。
|
||||
|
||||
---
|
||||
|
||||
## 通过电子邮件管理客户
|
||||
|
||||
### 通过电子邮件获取客户
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/inbounds/:id/clients/email/:email`
|
||||
- **描述**: 通过电子邮件获取客户信息。
|
||||
|
||||
### 获取客户 IP 地址
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/inbounds/:id/clients/email/:email/ips`
|
||||
- **描述**: 通过电子邮件获取客户的 IP 地址列表。
|
||||
|
||||
### 清除客户 IP 地址
|
||||
- **方法**: `DELETE`
|
||||
- **端点**: `/inbounds/:id/clients/email/:email/ips`
|
||||
- **描述**: 清除客户的 IP 地址列表。
|
||||
|
||||
### 通过电子邮件获取客户流量
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/inbounds/:id/clients/email/:email/traffic`
|
||||
- **描述**: 通过电子邮件获取客户流量统计信息。
|
||||
|
||||
### 通过电子邮件重置客户流量
|
||||
- **方法**: `DELETE`
|
||||
- **端点**: `/inbounds/:id/clients/email/:email/traffic`
|
||||
- **描述**: 通过电子邮件重置客户流量。
|
||||
|
||||
---
|
||||
|
||||
## 其他功能
|
||||
|
||||
### 创建备份
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/inbounds/create-backup`
|
||||
- **描述**: 创建数据备份。
|
||||
|
||||
### 获取在线客户
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/inbounds/online`
|
||||
- **描述**: 获取在线客户列表。
|
||||
|
||||
---
|
||||
|
||||
## 服务器
|
||||
|
||||
### 获取服务器状态
|
||||
- **方法**: `GET`
|
||||
- **端点**: `/server/status`
|
||||
- **描述**: 获取服务器状态。
|
137
docs/API.en.md
Normal file
137
docs/API.en.md
Normal file
|
@ -0,0 +1,137 @@
|
|||
# API Documentation
|
||||
|
||||
## Inbounds
|
||||
|
||||
### Get All Inbounds
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/`
|
||||
- **Description**: Retrieve a list of all inbounds.
|
||||
|
||||
### Reset All Client Traffic
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/traffic`
|
||||
- **Description**: Reset the traffic of all clients.
|
||||
|
||||
---
|
||||
|
||||
## Inbound
|
||||
|
||||
### Add Inbound
|
||||
- **Method**: `POST`
|
||||
- **Endpoint**: `/inbounds/`
|
||||
- **Description**: Add a new inbound.
|
||||
|
||||
### Get Inbound by ID
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id`
|
||||
- **Description**: Retrieve information about a specific inbound by its ID.
|
||||
|
||||
### Delete Inbound by ID
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id`
|
||||
- **Description**: Delete an inbound by its ID.
|
||||
|
||||
### Update Inbound by ID
|
||||
- **Method**: `PUT`
|
||||
- **Endpoint**: `/inbounds/:id`
|
||||
- **Description**: Update information about an inbound by its ID.
|
||||
|
||||
### Delete Inbound Traffic
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/traffic`
|
||||
- **Description**: Delete traffic for an inbound by its ID.
|
||||
|
||||
### Delete Depleted Clients
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/depleted-clients`
|
||||
- **Description**: Remove clients with exhausted traffic for a specific inbound.
|
||||
|
||||
---
|
||||
|
||||
## Inbound Clients
|
||||
|
||||
### Get Inbound Clients
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/`
|
||||
- **Description**: Retrieve a list of clients for a specific inbound.
|
||||
|
||||
---
|
||||
|
||||
## Inbound Client
|
||||
|
||||
### Add Inbound Client
|
||||
- **Method**: `POST`
|
||||
- **Endpoint**: `/inbounds/:id/clients`
|
||||
- **Description**: Add a new client to an inbound.
|
||||
|
||||
### Get Client by ID
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId`
|
||||
- **Description**: Retrieve information about a client by its ID.
|
||||
|
||||
### Update Inbound Client
|
||||
- **Method**: `PUT`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId`
|
||||
- **Description**: Update client information by its ID.
|
||||
|
||||
### Delete Inbound Client
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId`
|
||||
- **Description**: Delete a client by its ID.
|
||||
|
||||
### Get Client Traffic by ID
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId/traffic`
|
||||
- **Description**: Retrieve traffic statistics for a client by its ID.
|
||||
|
||||
---
|
||||
|
||||
## Inbound Client by Email
|
||||
|
||||
### Get Client by Email
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email`
|
||||
- **Description**: Retrieve client information by email.
|
||||
|
||||
### Get Client IPs
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/ips`
|
||||
- **Description**: Retrieve a list of client IP addresses by email.
|
||||
|
||||
### Clear Client IPs
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/ips`
|
||||
- **Description**: Clear the list of client IP addresses by email.
|
||||
|
||||
### Get Client Traffic by Email
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/traffic`
|
||||
- **Description**: Retrieve traffic statistics for a client by email.
|
||||
|
||||
### Reset Client Traffic by Email
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/traffic`
|
||||
- **Description**: Reset a client's traffic by email.
|
||||
|
||||
---
|
||||
|
||||
## Other
|
||||
|
||||
### Create Backup
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/create-backup`
|
||||
- **Description**: Create a data backup.
|
||||
|
||||
### Get Online Clients
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/online`
|
||||
- **Description**: Retrieve a list of online clients.
|
||||
|
||||
---
|
||||
|
||||
## Server
|
||||
|
||||
### Get Server Status
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/server/status`
|
||||
- **Description**: Retrieve the server status.
|
137
docs/API.es.md
Normal file
137
docs/API.es.md
Normal file
|
@ -0,0 +1,137 @@
|
|||
# API Documentation
|
||||
|
||||
## Inbounds
|
||||
|
||||
### Get All Inbounds
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/`
|
||||
- **Description**: Получить список всех inbounds.
|
||||
|
||||
### Reset All Client Traffics
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/traffic`
|
||||
- **Description**: Сбросить трафик всех клиентов.
|
||||
|
||||
---
|
||||
|
||||
## Inbound
|
||||
|
||||
### Add Inbound
|
||||
- **Method**: `POST`
|
||||
- **Endpoint**: `/inbounds/`
|
||||
- **Description**: Добавить новый inbound.
|
||||
|
||||
### Get Inbound by ID
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id`
|
||||
- **Description**: Получить информацию о конкретном inbound по его ID.
|
||||
|
||||
### Delete Inbound by ID
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id`
|
||||
- **Description**: Удалить inbound по его ID.
|
||||
|
||||
### Update Inbound by ID
|
||||
- **Method**: `PUT`
|
||||
- **Endpoint**: `/inbounds/:id`
|
||||
- **Description**: Обновить информацию о inbound по его ID.
|
||||
|
||||
### Delete Inbound Traffic
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/traffic`
|
||||
- **Description**: Удалить трафик inbound по его ID.
|
||||
|
||||
### Delete Depleted Clients
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/depleted-clients`
|
||||
- **Description**: Удалить клиентов с исчерпанным трафиком для конкретного inbound.
|
||||
|
||||
---
|
||||
|
||||
## Inbound Clients
|
||||
|
||||
### Get Inbound Clients
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/`
|
||||
- **Description**: Получить список клиентов для конкретного inbound.
|
||||
|
||||
---
|
||||
|
||||
## Inbound Client
|
||||
|
||||
### Add Inbound Client
|
||||
- **Method**: `POST`
|
||||
- **Endpoint**: `/inbounds/:id/clients`
|
||||
- **Description**: Добавить нового клиента к inbound.
|
||||
|
||||
### Get Client by ID
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId`
|
||||
- **Description**: Получить информацию о клиенте по его ID.
|
||||
|
||||
### Update Inbound Client
|
||||
- **Method**: `PUT`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId`
|
||||
- **Description**: Обновить информацию о клиенте по его ID.
|
||||
|
||||
### Delete Inbound Client
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId`
|
||||
- **Description**: Удалить клиента по его ID.
|
||||
|
||||
### Get Client Traffics by ID
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId/traffic`
|
||||
- **Description**: Получить статистику трафика клиента по его ID.
|
||||
|
||||
---
|
||||
|
||||
## Inbound Client by Email
|
||||
|
||||
### Get Client by Email
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email`
|
||||
- **Description**: Получить информацию о клиенте по его email.
|
||||
|
||||
### Get Client IPs
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/ips`
|
||||
- **Description**: Получить список IP-адресов клиента по его email.
|
||||
|
||||
### Clear Client IPs
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/ips`
|
||||
- **Description**: Очистить список IP-адресов клиента по его email.
|
||||
|
||||
### Get Client Traffics by Email
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/traffic`
|
||||
- **Description**: Получить статистику трафика клиента по его email.
|
||||
|
||||
### Reset Client Traffic by Email
|
||||
- **Method**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/traffic`
|
||||
- **Description**: Сбросить трафик клиента по его email.
|
||||
|
||||
---
|
||||
|
||||
## Other
|
||||
|
||||
### Create Backup
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/create-backup`
|
||||
- **Description**: Создать резервную копию данных.
|
||||
|
||||
### Get Online Clients
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/inbounds/online`
|
||||
- **Description**: Получить список онлайн-клиентов.
|
||||
|
||||
---
|
||||
|
||||
## Server
|
||||
|
||||
### Get Server Status
|
||||
- **Method**: `GET`
|
||||
- **Endpoint**: `/server/status`
|
||||
- **Description**: Получить статус сервера.
|
137
docs/API.ru.md
Normal file
137
docs/API.ru.md
Normal file
|
@ -0,0 +1,137 @@
|
|||
# Documentación de la API
|
||||
|
||||
## Inbounds
|
||||
|
||||
### Obtener todos los Inbounds
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/inbounds/`
|
||||
- **Descripción**: Obtener una lista de todos los inbounds.
|
||||
|
||||
### Restablecer todo el tráfico de clientes
|
||||
- **Método**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/traffic`
|
||||
- **Descripción**: Restablecer el tráfico de todos los clientes.
|
||||
|
||||
---
|
||||
|
||||
## Inbound
|
||||
|
||||
### Agregar Inbound
|
||||
- **Método**: `POST`
|
||||
- **Endpoint**: `/inbounds/`
|
||||
- **Descripción**: Agregar un nuevo inbound.
|
||||
|
||||
### Obtener Inbound por ID
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id`
|
||||
- **Descripción**: Obtener información sobre un inbound específico por su ID.
|
||||
|
||||
### Eliminar Inbound por ID
|
||||
- **Método**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id`
|
||||
- **Descripción**: Eliminar un inbound por su ID.
|
||||
|
||||
### Actualizar Inbound por ID
|
||||
- **Método**: `PUT`
|
||||
- **Endpoint**: `/inbounds/:id`
|
||||
- **Descripción**: Actualizar la información de un inbound por su ID.
|
||||
|
||||
### Eliminar tráfico de Inbound
|
||||
- **Método**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/traffic`
|
||||
- **Descripción**: Eliminar el tráfico de un inbound por su ID.
|
||||
|
||||
### Eliminar clientes con tráfico agotado
|
||||
- **Método**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/depleted-clients`
|
||||
- **Descripción**: Eliminar clientes con tráfico agotado para un inbound específico.
|
||||
|
||||
---
|
||||
|
||||
## Clientes de Inbound
|
||||
|
||||
### Obtener clientes de Inbound
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/`
|
||||
- **Descripción**: Obtener una lista de clientes para un inbound específico.
|
||||
|
||||
---
|
||||
|
||||
## Cliente de Inbound
|
||||
|
||||
### Agregar cliente de Inbound
|
||||
- **Método**: `POST`
|
||||
- **Endpoint**: `/inbounds/:id/clients`
|
||||
- **Descripción**: Agregar un nuevo cliente a un inbound.
|
||||
|
||||
### Obtener cliente por ID
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId`
|
||||
- **Descripción**: Obtener información sobre un cliente por su ID.
|
||||
|
||||
### Actualizar cliente de Inbound
|
||||
- **Método**: `PUT`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId`
|
||||
- **Descripción**: Actualizar la información del cliente por su ID.
|
||||
|
||||
### Eliminar cliente de Inbound
|
||||
- **Método**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId`
|
||||
- **Descripción**: Eliminar un cliente por su ID.
|
||||
|
||||
### Obtener tráfico del cliente por ID
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/:clientId/traffic`
|
||||
- **Descripción**: Obtener estadísticas de tráfico para un cliente por su ID.
|
||||
|
||||
---
|
||||
|
||||
## Cliente de Inbound por correo electrónico
|
||||
|
||||
### Obtener cliente por correo electrónico
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email`
|
||||
- **Descripción**: Obtener información del cliente por correo electrónico.
|
||||
|
||||
### Obtener IPs del cliente
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/ips`
|
||||
- **Descripción**: Obtener una lista de direcciones IP del cliente por correo electrónico.
|
||||
|
||||
### Limpiar IPs del cliente
|
||||
- **Método**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/ips`
|
||||
- **Descripción**: Limpiar la lista de direcciones IP del cliente por correo electrónico.
|
||||
|
||||
### Obtener tráfico del cliente por correo electrónico
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/traffic`
|
||||
- **Descripción**: Obtener estadísticas de tráfico para un cliente por correo electrónico.
|
||||
|
||||
### Restablecer tráfico del cliente por correo electrónico
|
||||
- **Método**: `DELETE`
|
||||
- **Endpoint**: `/inbounds/:id/clients/email/:email/traffic`
|
||||
- **Descripción**: Restablecer el tráfico de un cliente por correo electrónico.
|
||||
|
||||
---
|
||||
|
||||
## Otros
|
||||
|
||||
### Crear copia de seguridad
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/inbounds/create-backup`
|
||||
- **Descripción**: Crear una copia de seguridad de los datos.
|
||||
|
||||
### Obtener clientes en línea
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/inbounds/online`
|
||||
- **Descripción**: Obtener una lista de clientes en línea.
|
||||
|
||||
---
|
||||
|
||||
## Servidor
|
||||
|
||||
### Obtener estado del servidor
|
||||
- **Método**: `GET`
|
||||
- **Endpoint**: `/server/status`
|
||||
- **Descripción**: Obtener el estado del servidor.
|
|
@ -8,52 +8,126 @@ import (
|
|||
|
||||
type APIController struct {
|
||||
BaseController
|
||||
inboundController *InboundController
|
||||
inbounds *InboundController
|
||||
Tgbot service.Tgbot
|
||||
server *ServerController
|
||||
}
|
||||
|
||||
func NewAPIController(g *gin.RouterGroup) *APIController {
|
||||
a := &APIController{}
|
||||
a.initRouter(g)
|
||||
a.initApiV2Router(g)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *APIController) initRouter(g *gin.RouterGroup) {
|
||||
g = g.Group("/panel/api/inbounds")
|
||||
g.Use(a.checkLogin)
|
||||
func (controller *APIController) initRouter(router *gin.RouterGroup) {
|
||||
apiV1 := router.Group("/panel/api")
|
||||
apiV1.Use(controller.checkLogin)
|
||||
|
||||
a.inboundController = NewInboundController(g)
|
||||
inboundsApiGroup := apiV1.Group("/inbounds")
|
||||
controller.inbounds = NewInboundController(inboundsApiGroup)
|
||||
|
||||
inboundRoutes := []struct {
|
||||
Method string
|
||||
Path string
|
||||
Handler gin.HandlerFunc
|
||||
}{
|
||||
{"GET", "/createbackup", a.createBackup},
|
||||
{"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},
|
||||
{"POST", "/clientIps/:email", a.inboundController.getClientIps},
|
||||
{"POST", "/clearClientIps/:email", a.inboundController.clearClientIps},
|
||||
{"POST", "/addClient", a.inboundController.addInboundClient},
|
||||
{"POST", "/:id/delClient/:clientId", a.inboundController.delInboundClient},
|
||||
{"POST", "/updateClient/:clientId", a.inboundController.updateInboundClient},
|
||||
{"POST", "/:id/resetClientTraffic/:email", a.inboundController.resetClientTraffic},
|
||||
{"POST", "/resetAllTraffics", a.inboundController.resetAllTraffics},
|
||||
{"POST", "/resetAllClientTraffics/:id", a.inboundController.resetAllClientTraffics},
|
||||
{"POST", "/delDepletedClients/:id", a.inboundController.delDepletedClients},
|
||||
{"POST", "/onlines", a.inboundController.onlines},
|
||||
{"GET", "/createbackup", controller.createBackup},
|
||||
{"GET", "/list", controller.inbounds.getInbounds},
|
||||
{"GET", "/get/:id", controller.inbounds.getInbound},
|
||||
{"GET", "/getClientTraffics/:email", controller.inbounds.getClientTraffics},
|
||||
{"GET", "/getClientTrafficsById/:id", controller.inbounds.getClientTrafficsById},
|
||||
{"POST", "/add", controller.inbounds.addInbound},
|
||||
{"POST", "/del/:id", controller.inbounds.delInbound},
|
||||
{"POST", "/update/:id", controller.inbounds.updateInbound},
|
||||
{"POST", "/clientIps/:email", controller.inbounds.getClientIps},
|
||||
{"POST", "/clearClientIps/:email", controller.inbounds.clearClientIps},
|
||||
{"POST", "/addClient", controller.inbounds.addInboundClient},
|
||||
{"POST", "/:id/delClient/:clientId", controller.inbounds.delInboundClient},
|
||||
{"POST", "/updateClient/:clientId", controller.inbounds.updateInboundClient},
|
||||
{"POST", "/:id/resetClientTraffic/:email", controller.inbounds.resetClientTraffic},
|
||||
{"POST", "/resetAllTraffics", controller.inbounds.resetAllTraffics},
|
||||
{"POST", "/resetAllClientTraffics/:id", controller.inbounds.resetAllClientTraffics},
|
||||
{"POST", "/delDepletedClients/:id", controller.inbounds.delDepletedClients},
|
||||
{"POST", "/onlines", controller.inbounds.onlines},
|
||||
}
|
||||
|
||||
for _, route := range inboundRoutes {
|
||||
g.Handle(route.Method, route.Path, route.Handler)
|
||||
inboundsApiGroup.Handle(route.Method, route.Path, route.Handler)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) createBackup(c *gin.Context) {
|
||||
a.Tgbot.SendBackupToAdmins()
|
||||
}
|
||||
|
||||
|
||||
func (controller *APIController) initApiV2Router(router *gin.RouterGroup) {
|
||||
apiV2 := router.Group("/api/v2")
|
||||
apiV2.Use(controller.checkLogin)
|
||||
|
||||
serverApiGroup := apiV2.Group("/server")
|
||||
inboundsApiGroup := apiV2.Group("/inbounds")
|
||||
|
||||
controller.inbounds = NewInboundController(inboundsApiGroup)
|
||||
controller.server = NewServerController(serverApiGroup)
|
||||
|
||||
/**
|
||||
* Inbounds
|
||||
*/
|
||||
inboundsApiGroup.GET("/", controller.inbounds.getInbounds)
|
||||
inboundsApiGroup.DELETE("/traffic", controller.inbounds.resetAllClientTraffics)
|
||||
|
||||
/**
|
||||
* Inbound
|
||||
*/
|
||||
inboundsApiGroup.POST("/", controller.inbounds.addInbound)
|
||||
inboundsApiGroup.GET("/:id", controller.inbounds.getInbound)
|
||||
inboundsApiGroup.DELETE("/:id", controller.inbounds.delInbound)
|
||||
inboundsApiGroup.PUT("/:id", controller.inbounds.updateInbound)
|
||||
|
||||
inboundsApiGroup.DELETE("/:id/traffic", controller.inbounds.delInbound)
|
||||
inboundsApiGroup.DELETE("/:id/depleted-clients", controller.inbounds.delDepletedClients)
|
||||
|
||||
/**
|
||||
* Inbound clients
|
||||
*/
|
||||
inboundsApiGroup.GET("/:id/clients/", controller.inbounds.getInboundClients)
|
||||
|
||||
/**
|
||||
* Inbound client
|
||||
*/
|
||||
inboundsApiGroup.POST("/:id/clients", controller.inbounds.addInboundClient)
|
||||
inboundsApiGroup.GET("/:id/clients/:clientId", controller.inbounds.getClientById)
|
||||
inboundsApiGroup.PUT("/:id/clients/:clientId", controller.inbounds.updateInboundClient)
|
||||
inboundsApiGroup.DELETE("/:id/clients/:clientId", controller.inbounds.delInboundClient)
|
||||
|
||||
inboundsApiGroup.GET("/:id/clients/:clientId/traffic", controller.inbounds.getClientTrafficsById)
|
||||
// TODO: get client ips by ID
|
||||
// TODO: client client ips by ID
|
||||
// TODO: reset client traffic by ID
|
||||
|
||||
/**
|
||||
* Inbound client by email
|
||||
*/
|
||||
inboundsApiGroup.GET("/:id/clients/email/:email", controller.inbounds.getClientByEmail)
|
||||
// TODO: update client by Email
|
||||
// TODO: delete client by Email
|
||||
|
||||
inboundsApiGroup.GET("/:id/clients/email/:email/ips", controller.inbounds.getClientIps)
|
||||
inboundsApiGroup.DELETE("/:id/clients/email/:email/ips", controller.inbounds.clearClientIps)
|
||||
|
||||
inboundsApiGroup.GET("/:id/clients/email/:email/traffic", controller.inbounds.getClientTraffics)
|
||||
inboundsApiGroup.DELETE("/:id/clients/email/:email/traffic", controller.inbounds.resetClientTraffic)
|
||||
|
||||
/**
|
||||
* Other
|
||||
*/
|
||||
inboundsApiGroup.GET("/create-backup", controller.createBackup)
|
||||
inboundsApiGroup.GET("/online", controller.inbounds.onlines)
|
||||
|
||||
/**
|
||||
* Server
|
||||
*/
|
||||
serverApiGroup.GET("/status", controller.server.status)
|
||||
}
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"errors"
|
||||
|
||||
"x-ui/database/model"
|
||||
"x-ui/web/service"
|
||||
|
@ -146,6 +147,60 @@ func (a *InboundController) updateInbound(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func (a *InboundController) getInboundClients(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil {
|
||||
jsonMsg(c, "GetInboundClients", errors.New("Incorrect inbound id"))
|
||||
return
|
||||
}
|
||||
|
||||
client, err := a.inboundService.GetInboundClients(id)
|
||||
if err != nil {
|
||||
jsonMsg(c, "GetInboundClientById", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonObj(c, client, nil)
|
||||
}
|
||||
|
||||
func (a *InboundController) getClientById(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil {
|
||||
jsonMsg(c, "GetInboundClientById", errors.New("Incorrect inbound id"))
|
||||
return
|
||||
}
|
||||
|
||||
client, err := a.inboundService.GetInboundClientById(id, c.Param("clientId"))
|
||||
if err != nil {
|
||||
jsonMsg(c, "GetInboundClientById", err)
|
||||
return
|
||||
}
|
||||
if client == nil {
|
||||
jsonMsg(c, "GetInboundClientById", errors.New("Client not found"))
|
||||
return
|
||||
}
|
||||
jsonObj(c, client, nil)
|
||||
}
|
||||
|
||||
func (a *InboundController) getClientByEmail(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil {
|
||||
jsonMsg(c, "GetInboundClientByEmail", errors.New("Incorrect inbound id"))
|
||||
return
|
||||
}
|
||||
|
||||
client, err := a.inboundService.GetInboundClientByEmail(id, c.Param("email"))
|
||||
if err != nil {
|
||||
jsonMsg(c, "GetInboundClientByEmail", err)
|
||||
return
|
||||
}
|
||||
if client == nil {
|
||||
jsonMsg(c, "GetInboundClientByEmail", errors.New("Client not found"))
|
||||
return
|
||||
}
|
||||
jsonObj(c, client, nil)
|
||||
}
|
||||
|
||||
func (a *InboundController) getClientIps(c *gin.Context) {
|
||||
email := c.Param("email")
|
||||
|
||||
|
|
|
@ -1729,6 +1729,56 @@ func (s *InboundService) DelDepletedClients(id int) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *InboundService) GetInboundClients(inboundId int) (client []model.Client, err error) {
|
||||
inbound, err := s.GetInbound(inboundId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
clients, err := s.GetClients(inbound)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if (clients == nil) {
|
||||
return make([]model.Client, 0), nil
|
||||
}
|
||||
return clients, nil
|
||||
}
|
||||
|
||||
func (s *InboundService) GetInboundClientById(inboundId int, clientId string) (client *model.Client, err error) {
|
||||
inbound, err := s.GetInbound(inboundId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clients, err := s.GetClients(inbound)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, client := range clients {
|
||||
if client.ID == clientId {
|
||||
return &client, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *InboundService) GetInboundClientByEmail(inboundId int, email string) (client *model.Client, err error) {
|
||||
inbound, err := s.GetInbound(inboundId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
clients, err := s.GetClients(inbound)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, client := range clients {
|
||||
if client.Email == email {
|
||||
return &client, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *InboundService) GetClientTrafficTgBot(tgId int64) ([]*xray.ClientTraffic, error) {
|
||||
db := database.GetDB()
|
||||
var inbounds []*model.Inbound
|
||||
|
|
Loading…
Reference in a new issue