diff --git a/cmd/dashboard/controller/nat.go b/cmd/dashboard/controller/nat.go index 8a6156f..69afe8e 100644 --- a/cmd/dashboard/controller/nat.go +++ b/cmd/dashboard/controller/nat.go @@ -64,6 +64,7 @@ func createNAT(c *gin.Context) (uint64, error) { uid := getUid(c) n.UserID = uid + n.Enabled = nf.Enabled n.Name = nf.Name n.Domain = nf.Domain n.Host = nf.Host @@ -121,6 +122,7 @@ func updateNAT(c *gin.Context) (any, error) { return nil, singleton.Localizer.ErrorT("permission denied") } + n.Enabled = nf.Enabled n.Name = nf.Name n.Domain = nf.Domain n.Host = nf.Host diff --git a/cmd/dashboard/main.go b/cmd/dashboard/main.go index 0dc6e32..ba3b350 100644 --- a/cmd/dashboard/main.go +++ b/cmd/dashboard/main.go @@ -13,12 +13,14 @@ import ( "time" _ "time/tzdata" + "github.com/gin-gonic/gin" "github.com/ory/graceful" "golang.org/x/crypto/bcrypt" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" "github.com/nezhahq/nezha/cmd/dashboard/controller" + "github.com/nezhahq/nezha/cmd/dashboard/controller/waf" "github.com/nezhahq/nezha/cmd/dashboard/rpc" "github.com/nezhahq/nezha/model" "github.com/nezhahq/nezha/proto" @@ -147,6 +149,11 @@ func newHTTPandGRPCMux(httpHandler http.Handler, grpcHandler http.Handler) http. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { natConfig := singleton.GetNATConfigByDomain(r.Host) if natConfig != nil { + if !natConfig.Enabled { + c, _ := gin.CreateTestContext(w) + waf.ShowBlockPage(c, fmt.Errorf("nat host %s is disabled", natConfig.Domain)) + return + } rpc.ServeNAT(w, r, natConfig) return } diff --git a/model/nat.go b/model/nat.go index f43ab0f..c5cbec8 100644 --- a/model/nat.go +++ b/model/nat.go @@ -2,6 +2,7 @@ package model type NAT struct { Common + Enabled bool `json:"enabled"` Name string `json:"name"` ServerID uint64 `json:"server_id"` Host string `json:"host"` diff --git a/model/nat_api.go b/model/nat_api.go index 97e4738..15ea212 100644 --- a/model/nat_api.go +++ b/model/nat_api.go @@ -2,6 +2,7 @@ package model type NATForm struct { Name string `json:"name,omitempty" minLength:"1"` + Enabled bool `json:"enabled,omitempty"` ServerID uint64 `json:"server_id,omitempty"` Host string `json:"host,omitempty"` Domain string `json:"domain,omitempty"` diff --git a/service/singleton/frontend-templates.yaml b/service/singleton/frontend-templates.yaml index b20f527..f244519 100644 --- a/service/singleton/frontend-templates.yaml +++ b/service/singleton/frontend-templates.yaml @@ -2,7 +2,7 @@ name: "OfficialAdmin" repository: "https://github.com/nezhahq/admin-frontend" author: "nezhahq" - version: "v1.6.1" + version: "v1.6.2" isadmin: true isofficial: true - path: "user-dist"