From 8c824595f4fbb0e666ee8fbe528e384c850405d6 Mon Sep 17 00:00:00 2001 From: luorijun Date: Mon, 19 May 2025 10:57:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=8C=87=E9=92=88=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AD=98=E5=82=A8=E7=99=BD=E5=90=8D=E5=8D=95=E3=80=81?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=92=8C=E5=AF=86=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E6=89=B9=E9=87=8F=E4=BC=A0=E5=85=A5=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gateway/core/auth.go | 6 +++--- gateway/fwd/auth/auth.go | 8 ++++---- gateway/web/handlers/auth.go | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gateway/core/auth.go b/gateway/core/auth.go index 57c6eb0..50b9fc3 100644 --- a/gateway/core/auth.go +++ b/gateway/core/auth.go @@ -4,7 +4,7 @@ import "time" type Permit struct { Expire time.Time `json:"expire"` - Whitelists []string `json:"whitelists"` - Username string `json:"username"` - Password string `json:"password"` + Whitelists *[]string `json:"whitelists"` + Username *string `json:"username"` + Password *string `json:"password"` } diff --git a/gateway/fwd/auth/auth.go b/gateway/fwd/auth/auth.go index 283f722..07a7bd2 100644 --- a/gateway/fwd/auth/auth.go +++ b/gateway/fwd/auth/auth.go @@ -47,9 +47,9 @@ func Protect(conn net.Conn, proto Protocol, username, password *string) (*core.A } // 检查 IP 是否可用 - if len(permit.Whitelists) > 0 { + if permit.Whitelists != nil && len(*permit.Whitelists) > 0 { var found = false - for _, allowedHost := range permit.Whitelists { + for _, allowedHost := range *permit.Whitelists { var allowed = net.ParseIP(allowedHost) var remote = net.ParseIP(remoteHost) if remote.Equal(allowed) { @@ -62,8 +62,8 @@ func Protect(conn net.Conn, proto Protocol, username, password *string) (*core.A } } - if username != nil && password != nil { - if *username != permit.Username || *password != permit.Password { + if permit.Username != nil || permit.Password != nil { + if *username != *permit.Username || *password != *permit.Password { return nil, errors.New("用户名或密码错误") } } diff --git a/gateway/web/handlers/auth.go b/gateway/web/handlers/auth.go index aa34e11..40bc04e 100644 --- a/gateway/web/handlers/auth.go +++ b/gateway/web/handlers/auth.go @@ -20,13 +20,15 @@ func Permit(ctx *fiber.Ctx) (err error) { } // 获取请求参数 - req, err := core.Decrypt[PermitReq](&sec, app.PlatformSecret) + req, err := core.Decrypt[[]PermitReq](&sec, app.PlatformSecret) if err != nil { return err } // 保存授权配置 - app.Permits.Store(req.Id, &req.Permit) + for _, permit := range *req { + app.Permits.Store(permit.Id, &permit.Permit) + } return nil }