feat: add compatible Trojan manager image

This commit is contained in:
chermack
2026-07-26 05:01:15 +08:00
parent 059be96536
commit cb17d56cae
26 changed files with 320 additions and 41 deletions
+12
View File
@@ -8,6 +8,7 @@ import (
"io/fs"
"net/http"
"strconv"
"trojan/managerconfig"
"trojan/core"
"trojan/util"
"trojan/web/controller"
@@ -171,6 +172,14 @@ func noTokenRouter(router *gin.Engine) {
})
}
func systemRouter(router *gin.Engine) {
system := router.Group("/system")
system.GET("/config", func(c *gin.Context) { if !RequireAdmin(c) { return }; c.JSON(200, controller.SystemConfig()) })
system.POST("/config/validate", func(c *gin.Context) { if !RequireAdmin(c) { return }; var cfg managerconfig.Config; if err:=c.ShouldBindJSON(&cfg); err!=nil { c.JSON(400, gin.H{"message":err.Error()}); return }; c.JSON(200, controller.ValidateSystemConfig(cfg)) })
system.POST("/config/apply", func(c *gin.Context) { if !RequireAdmin(c) { return }; var cfg managerconfig.Config; if err:=c.ShouldBindJSON(&cfg); err!=nil { c.JSON(400, gin.H{"message":err.Error()}); return }; c.JSON(200, controller.ApplySystemConfig(cfg)) })
system.GET("/certificate", func(c *gin.Context) { if !RequireAdmin(c) { return }; c.JSON(200, controller.CertificateStatus()) })
}
// Start web启动入口
func Start(host string, port, timeout int, isSSL bool) {
router := gin.Default()
@@ -178,7 +187,10 @@ func Start(host string, port, timeout int, isSSL bool) {
router.Use(gzip.Gzip(gzip.DefaultCompression))
staticRouter(router)
noTokenRouter(router)
router.GET("/healthz", func(c *gin.Context) { c.JSON(200, gin.H{"status":"ok"}) })
router.GET("/readyz", func(c *gin.Context) { if core.GetConfig()==nil { c.JSON(503, gin.H{"status":"not ready"}); return }; c.JSON(200, gin.H{"status":"ready"}) })
router.Use(Auth(router, timeout).MiddlewareFunc())
systemRouter(router)
trojanRouter(router)
userRouter(router)
dataRouter(router)