Продакшн рефактор без легаси
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"hy2xs-admin/service"
|
||||
"hy2xs-admin/util"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -299,7 +300,7 @@ func ExportAccount(c *gin.Context) {
|
||||
}
|
||||
|
||||
fileName := fmt.Sprintf("AccountExport-%s.json", time.Now().Format("20060102150405"))
|
||||
filePath := constant.ExportPathDir + fileName
|
||||
filePath := filepath.Join(constant.ExportPathDir, fileName)
|
||||
|
||||
if err = util.ExportFile(filePath, accountExports, 0); err != nil {
|
||||
vo.Fail(err.Error(), c)
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"hy2xs-admin/service"
|
||||
"hy2xs-admin/util"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -230,7 +231,7 @@ func ExportHysteria2Config(c *gin.Context) {
|
||||
hysteria2ServerConfig.TrafficStats.Secret = &trafficStatsSecret
|
||||
|
||||
fileName := fmt.Sprintf("Hysteria2Config-%s.yaml", time.Now().Format("20060102150405"))
|
||||
filePath := constant.ExportPathDir + fileName
|
||||
filePath := filepath.Join(constant.ExportPathDir, fileName)
|
||||
|
||||
if err = util.ExportFile(filePath, hysteria2ServerConfig, 1); err != nil {
|
||||
vo.Fail(err.Error(), c)
|
||||
@@ -258,7 +259,7 @@ func ExportConfig(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
fileName := fmt.Sprintf("SystemConfig-%s.json", time.Now().Format("20060102150405"))
|
||||
filePath := constant.ExportPathDir + fileName
|
||||
filePath := filepath.Join(constant.ExportPathDir, fileName)
|
||||
|
||||
if err = util.ExportFile(filePath, configs, 0); err != nil {
|
||||
vo.Fail(err.Error(), c)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"hy2xs-admin/model/vo"
|
||||
)
|
||||
|
||||
func LocalOnlyHandler() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
host, _, err := net.SplitHostPort(c.Request.RemoteAddr)
|
||||
if err != nil {
|
||||
host = c.ClientIP()
|
||||
}
|
||||
|
||||
if host != "127.0.0.1" && host != "::1" {
|
||||
vo.Fail("local access only", c)
|
||||
c.AbortWithStatus(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,14 @@ import (
|
||||
"hy2xs-admin/controller"
|
||||
)
|
||||
|
||||
func initHysteria2AuthRouter(hysteria2Api *gin.RouterGroup) {
|
||||
func initHysteria2MachineAuthRouter(hysteria2Api *gin.RouterGroup) {
|
||||
hysteria2 := hysteria2Api.Group("/hysteria2")
|
||||
{
|
||||
hysteria2.POST("/auth", controller.Hysteria2Auth)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func initHysteria2SubscribeRouter(hysteria2Api *gin.RouterGroup) {
|
||||
hysteria2Api.GET("/:conPass", controller.Hysteria2Subscribe)
|
||||
}
|
||||
|
||||
|
||||
+23
-22
@@ -8,34 +8,35 @@ import (
|
||||
)
|
||||
|
||||
func Router(router *gin.Engine, huiWebContext *string) {
|
||||
// global context
|
||||
relativePath := "/"
|
||||
if huiWebContext != nil && strings.HasPrefix(*huiWebContext, "/") {
|
||||
relativePath = *huiWebContext
|
||||
}
|
||||
|
||||
frontend.InitFrontend(router, relativePath)
|
||||
|
||||
globalGroup := router.Group(relativePath)
|
||||
{
|
||||
globalGroup.Use(middleware.FilterHandler(), middleware.LogHandler(), middleware.RateLimiterHandler())
|
||||
|
||||
frontend.InitFrontend(router, relativePath)
|
||||
machineApi := globalGroup.Group("/hui")
|
||||
machineApi.Use(middleware.LocalOnlyHandler(), middleware.LogHandler())
|
||||
initHysteria2MachineAuthRouter(machineApi)
|
||||
|
||||
authApi := globalGroup.Group("/hui")
|
||||
{
|
||||
initAuthRouter(authApi)
|
||||
initHysteria2AuthRouter(authApi)
|
||||
}
|
||||
authApi := globalGroup.Group("/hui")
|
||||
authApi.Use(middleware.FilterHandler(), middleware.LogHandler(), middleware.RateLimiterHandler())
|
||||
initAuthRouter(authApi)
|
||||
initHysteria2SubscribeRouter(authApi)
|
||||
|
||||
globalGroup.Use(middleware.JWTHandler())
|
||||
|
||||
globalGroup.Use(middleware.AdminHandler())
|
||||
|
||||
huiAdminApi := globalGroup.Group("/hui")
|
||||
{
|
||||
initAccountAdminRouter(huiAdminApi)
|
||||
initConfigRouter(huiAdminApi)
|
||||
initHysteria2Router(huiAdminApi)
|
||||
initLogRouter(huiAdminApi)
|
||||
initMonitorRouter(huiAdminApi)
|
||||
}
|
||||
}
|
||||
huiAdminApi := globalGroup.Group("/hui")
|
||||
huiAdminApi.Use(
|
||||
middleware.FilterHandler(),
|
||||
middleware.LogHandler(),
|
||||
middleware.RateLimiterHandler(),
|
||||
middleware.JWTHandler(),
|
||||
middleware.AdminHandler(),
|
||||
)
|
||||
initAccountAdminRouter(huiAdminApi)
|
||||
initConfigRouter(huiAdminApi)
|
||||
initHysteria2Router(huiAdminApi)
|
||||
initLogRouter(huiAdminApi)
|
||||
initMonitorRouter(huiAdminApi)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user