diff --git a/config/config.go b/config/config.go index 2c275530..30df7c0b 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,9 @@ var name string //go:embed default_xray.json var defaultXrayTemplate string +//go:embed test_xray.json +var testXrayTemplate string + type LogLevel string const ( @@ -93,3 +96,7 @@ func GetDBPath() string { func GetDefaultXrayTemplate() string { return defaultXrayTemplate } + +func GetTestXrayTemplate() string { + return testXrayTemplate +} diff --git a/config/test_xray.json b/config/test_xray.json new file mode 100644 index 00000000..2b87e247 --- /dev/null +++ b/config/test_xray.json @@ -0,0 +1,17 @@ +{ + "log": { + "loglevel": "none" + }, + "inbounds": [ + { + "tag": "http-test-in", + "listen": "127.0.0.1", + "port": __INBOUND_PORT__, + "protocol": "http", + "settings": {} + } + ], + "outbounds": [ + __OUTBOUND__ + ] +} diff --git a/web/assets/js/model/setting.js b/web/assets/js/model/setting.js index b1ef55ae..a74e3373 100644 --- a/web/assets/js/model/setting.js +++ b/web/assets/js/model/setting.js @@ -12,6 +12,7 @@ class AllSetting { this.expireDiff = ""; this.trafficDiff = ""; this.remarkModel = "-ieo"; + this.outboundTestUrl = "https://www.gstatic.com/generate_204"; this.tgBotEnable = false; this.tgBotToken = ""; this.tgBotChatId = ""; diff --git a/web/controller/outbound.go b/web/controller/outbound.go index bffa9f6d..64031b9e 100644 --- a/web/controller/outbound.go +++ b/web/controller/outbound.go @@ -30,6 +30,7 @@ func (a *OutboundController) initRouter(g *gin.RouterGroup) { g.POST("/:id/resetTraffic", a.resetTraffic) g.POST("/resetAllTraffics", a.resetAllTraffics) g.POST("/onlines", a.onlines) + g.POST("/test", a.test) } func (a *OutboundController) getOutbounds(c *gin.Context) { @@ -116,3 +117,13 @@ func (a *OutboundController) resetAllTraffics(c *gin.Context) { func (a *OutboundController) onlines(c *gin.Context) { jsonObj(c, a.outboundService.GetOnlineOutbounds(), nil) } + +func (a *OutboundController) test(c *gin.Context) { + id, err := strconv.Atoi(c.PostForm("id")) + if err != nil { + jsonMsg(c, I18nWeb(c, "pages.outbounds.test"), err) + return + } + result, err := a.outboundService.TestOutbound(id) + jsonObj(c, result, err) +} diff --git a/web/entity/entity.go b/web/entity/entity.go index 1a57e9c9..e50b7006 100644 --- a/web/entity/entity.go +++ b/web/entity/entity.go @@ -27,6 +27,7 @@ type AllSetting struct { ExpireDiff int `json:"expireDiff" form:"expireDiff"` TrafficDiff int `json:"trafficDiff" form:"trafficDiff"` RemarkModel string `json:"remarkModel" form:"remarkModel"` + OutboundTestUrl string `json:"outboundTestUrl" form:"outboundTestUrl"` TgBotEnable bool `json:"tgBotEnable" form:"tgBotEnable"` TgBotToken string `json:"tgBotToken" form:"tgBotToken"` TgBotChatId string `json:"tgBotChatId" form:"tgBotChatId"` diff --git a/web/html/xui/outbounds.html b/web/html/xui/outbounds.html index 34b6e1a8..c5e7f3bc 100644 --- a/web/html/xui/outbounds.html +++ b/web/html/xui/outbounds.html @@ -90,6 +90,10 @@ + + + {{ i18n "pages.outbounds.testAll" }} + {{ i18n "pages.outbounds.resetAllTraffic" }} @@ -167,6 +171,29 @@ +