feat: disable nat

This commit is contained in:
naiba
2025-01-21 22:23:15 +08:00
parent 9791c81a03
commit 7831e2d1f8
5 changed files with 12 additions and 1 deletions

View File

@@ -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

View File

@@ -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
}