mirror of
https://github.com/alireza0/x-ui.git
synced 2026-03-14 05:23:09 +00:00
[api] add server endpoint #1590
This commit is contained in:
23
README.md
23
README.md
@@ -209,7 +209,6 @@ docker build -t x-ui .
|
||||
| :----: | --------------------------------- | ----------------------------------------- |
|
||||
| `GET` | `"/"` | Get all inbounds |
|
||||
| `GET` | `"/get/:id"` | Get inbound with inbound.id |
|
||||
| `GET` | `"/createbackup"` | Telegram bot sends backup to admins |
|
||||
| `POST` | `"/add"` | Add inbound |
|
||||
| `POST` | `"/del/:id"` | Delete inbound |
|
||||
| `POST` | `"/update/:id"` | Update inbound |
|
||||
@@ -224,12 +223,34 @@ docker build -t x-ui .
|
||||
| `POST` | `"/delDepletedClients/:id"` | Delete inbound depleted clients (-1: all) |
|
||||
| `POST` | `"/onlines"` | Get online users ( list of emails ) |
|
||||
|
||||
|
||||
\*- The field `clientId` should be filled by:
|
||||
|
||||
- `client.id` for VMess and VLESS
|
||||
- `client.password` for Trojan
|
||||
- `client.email` for Shadowsocks
|
||||
|
||||
|
||||
- `/xui/API/server` base for following actions:
|
||||
|
||||
| Method | Path | Action |
|
||||
| :----: | --------------------------------- | ----------------------------------------- |
|
||||
| `GET` | `"/status"` | Get server status |
|
||||
| `GET` | `"/getDb"` | Get database backup |
|
||||
| `GET` | `"/createbackup"` | Telegram bot sends backup to admins |
|
||||
| `GET` | `"/getConfigJson"` | Get config.json |
|
||||
| `GET` | `"/getXrayVersion"` | Get last xray versions |
|
||||
| `GET` | `"/getNewVlessEnc"` | Get new vless enc |
|
||||
| `GET` | `"/getNewX25519Cert"` | Get new x25519 cert |
|
||||
| `GET` | `"/getNewmldsa65"` | Get new mldsa65 |
|
||||
| `POST` | `"/getNewEchCert"` | Get new ech cert |
|
||||
| `POST` | `"/importDB"` | Import database to x-ui |
|
||||
| `POST` | `"/stopXrayService"` | Stop xray service |
|
||||
| `POST` | `"/restartXrayService"` | Restart xray service |
|
||||
| `POST` | `"/installXray/:version"` | Install specific version of xray |
|
||||
| `POST` | `"/logs/:count"` | Get panel/xray logs |
|
||||
|
||||
|
||||
</details>
|
||||
|
||||
## Environment Variables
|
||||
|
||||
@@ -9,27 +9,36 @@ import (
|
||||
type APIController struct {
|
||||
BaseController
|
||||
inboundController *InboundController
|
||||
serverController *ServerController
|
||||
Tgbot service.Tgbot
|
||||
}
|
||||
|
||||
func NewAPIController(g *gin.RouterGroup) *APIController {
|
||||
a := &APIController{}
|
||||
func NewAPIController(g *gin.RouterGroup, s *ServerController) *APIController {
|
||||
a := &APIController{
|
||||
serverController: s,
|
||||
}
|
||||
a.initRouter(g)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *APIController) initRouter(g *gin.RouterGroup) {
|
||||
g = g.Group("/xui/API/inbounds")
|
||||
g.Use(a.checkLogin)
|
||||
api := g.Group("/xui/API")
|
||||
api.Use(a.checkLogin)
|
||||
|
||||
a.inboundController = NewInboundController(g)
|
||||
a.inboundApi(api)
|
||||
a.serverApi(api)
|
||||
}
|
||||
|
||||
func (a *APIController) inboundApi(api *gin.RouterGroup) {
|
||||
inboundsApi := api.Group("/inbounds")
|
||||
|
||||
a.inboundController = &InboundController{}
|
||||
|
||||
inboundRoutes := []struct {
|
||||
Method string
|
||||
Path string
|
||||
Handler gin.HandlerFunc
|
||||
}{
|
||||
{"GET", "/createbackup", a.createBackup},
|
||||
{"GET", "/", a.inboundController.getInbounds},
|
||||
{"GET", "/get/:id", a.inboundController.getInbound},
|
||||
{"GET", "/getClientTraffics/:email", a.inboundController.getClientTraffics},
|
||||
@@ -48,7 +57,37 @@ func (a *APIController) initRouter(g *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
for _, route := range inboundRoutes {
|
||||
g.Handle(route.Method, route.Path, route.Handler)
|
||||
inboundsApi.Handle(route.Method, route.Path, route.Handler)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) serverApi(api *gin.RouterGroup) {
|
||||
serverApi := api.Group("/server")
|
||||
|
||||
serverRoutes := []struct {
|
||||
Method string
|
||||
Path string
|
||||
Handler gin.HandlerFunc
|
||||
}{
|
||||
{"GET", "/status", a.serverController.status},
|
||||
{"GET", "/getDb", a.serverController.getDb},
|
||||
{"GET", "/createbackup", a.createBackup},
|
||||
{"GET", "/getConfigJson", a.serverController.getConfigJson},
|
||||
{"GET", "/getXrayVersion", a.serverController.getXrayVersion},
|
||||
{"GET", "/getNewVlessEnc", a.serverController.getNewVlessEnc},
|
||||
{"GET", "/getNewX25519Cert", a.serverController.getNewX25519Cert},
|
||||
{"GET", "/getNewmldsa65", a.serverController.getNewmldsa65},
|
||||
|
||||
{"POST", "/getNewEchCert", a.serverController.getNewEchCert},
|
||||
{"POST", "/importDB", a.serverController.importDB},
|
||||
{"POST", "/stopXrayService", a.serverController.stopXrayService},
|
||||
{"POST", "/restartXrayService", a.serverController.restartXrayService},
|
||||
{"POST", "/installXray/:version", a.serverController.installXray},
|
||||
{"POST", "/logs/:count", a.serverController.getLogs},
|
||||
}
|
||||
|
||||
for _, route := range serverRoutes {
|
||||
serverApi.Handle(route.Method, route.Path, route.Handler)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,20 +39,20 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) {
|
||||
g = g.Group("/server")
|
||||
|
||||
g.Use(a.checkLogin)
|
||||
g.GET("/status", a.status)
|
||||
g.GET("/getDb", a.getDb)
|
||||
g.GET("/getConfigJson", a.getConfigJson)
|
||||
g.GET("/getNewmldsa65", a.getNewmldsa65)
|
||||
g.GET("/getNewVlessEnc", a.getNewVlessEnc)
|
||||
g.GET("/getXrayVersion", a.getXrayVersion)
|
||||
g.GET("/getNewX25519Cert", a.getNewX25519Cert)
|
||||
|
||||
g.POST("/status", a.status)
|
||||
g.POST("/getXrayVersion", a.getXrayVersion)
|
||||
g.POST("/getNewEchCert", a.getNewEchCert)
|
||||
g.POST("/stopXrayService", a.stopXrayService)
|
||||
g.POST("/restartXrayService", a.restartXrayService)
|
||||
g.POST("/installXray/:version", a.installXray)
|
||||
g.POST("/logs/:count", a.getLogs)
|
||||
g.POST("/getConfigJson", a.getConfigJson)
|
||||
g.POST("/importDB", a.importDB)
|
||||
g.POST("/getNewX25519Cert", a.getNewX25519Cert)
|
||||
g.POST("/getNewmldsa65", a.getNewmldsa65)
|
||||
g.POST("/getNewEchCert", a.getNewEchCert)
|
||||
}
|
||||
|
||||
func (a *ServerController) refreshStatus() {
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
},
|
||||
async getNewX25519Cert(){
|
||||
inModal.loading(true);
|
||||
const msg = await HttpUtil.post('/server/getNewX25519Cert');
|
||||
const msg = await HttpUtil.get('/server/getNewX25519Cert');
|
||||
inModal.loading(false);
|
||||
if (!msg.success) {
|
||||
return;
|
||||
@@ -138,7 +138,7 @@
|
||||
},
|
||||
async getNewmldsa65() {
|
||||
inModal.loading(true);
|
||||
const msg = await HttpUtil.post('/server/getNewmldsa65');
|
||||
const msg = await HttpUtil.get('/server/getNewmldsa65');
|
||||
inModal.loading(false);
|
||||
if (!msg.success) {
|
||||
return;
|
||||
|
||||
@@ -535,7 +535,7 @@
|
||||
this.loadingTip = tip;
|
||||
},
|
||||
async getStatus() {
|
||||
const msg = await HttpUtil.post('/server/status');
|
||||
const msg = await HttpUtil.get('/server/status');
|
||||
if (msg.success) {
|
||||
this.setStatus(msg.obj);
|
||||
}
|
||||
@@ -545,7 +545,7 @@
|
||||
},
|
||||
async openSelectV2rayVersion() {
|
||||
this.loading(true);
|
||||
const msg = await HttpUtil.post('server/getXrayVersion');
|
||||
const msg = await HttpUtil.get('server/getXrayVersion');
|
||||
this.loading(false);
|
||||
if (!msg.success) {
|
||||
return;
|
||||
@@ -595,7 +595,7 @@
|
||||
},
|
||||
async openConfig() {
|
||||
this.loading(true);
|
||||
const msg = await HttpUtil.post('server/getConfigJson');
|
||||
const msg = await HttpUtil.get('server/getConfigJson');
|
||||
this.loading(false);
|
||||
if (!msg.success) {
|
||||
return;
|
||||
|
||||
@@ -228,7 +228,7 @@ func (s *Server) initRouter() (*gin.Engine, error) {
|
||||
s.index = controller.NewIndexController(g)
|
||||
s.server = controller.NewServerController(g)
|
||||
s.xui = controller.NewXUIController(g)
|
||||
s.api = controller.NewAPIController(g)
|
||||
s.api = controller.NewAPIController(g, s.server)
|
||||
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user