fix28: полный production-фикс графиков, machine-auth, i18n и peer import/export

This commit is contained in:
2026-05-09 02:14:59 +05:00
parent 3c569061fe
commit 1139c428b6
11 changed files with 230 additions and 28 deletions
+53
View File
@@ -0,0 +1,53 @@
package middleware
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
"hy2xs-admin/dao"
"hy2xs-admin/model/constant"
)
func MachineAuthHandler() gin.HandlerFunc {
return func(c *gin.Context) {
secretCfg, err := dao.GetConfig("key = ?", constant.Hysteria2TrafficStatsSecret)
if err != nil || secretCfg.Value == nil {
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{
"code": http.StatusForbidden,
"type": "no",
"message": "machine auth failed",
"data": nil,
})
return
}
expected := strings.TrimSpace(*secretCfg.Value)
if expected == "" {
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{
"code": http.StatusForbidden,
"type": "no",
"message": "machine auth not configured",
"data": nil,
})
return
}
provided := strings.TrimSpace(c.Query("access_token"))
if provided == "" {
provided = strings.TrimSpace(c.GetHeader("X-HY2XS-Machine-Token"))
}
if provided == "" || provided != expected {
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{
"code": http.StatusForbidden,
"type": "no",
"message": "machine auth failed",
"data": nil,
})
return
}
c.Next()
}
}