From 658db55d91d9caca9887262549e677bb3f95bde7 Mon Sep 17 00:00:00 2001 From: CityFun <31820853+zhengkunwang223@users.noreply.github.com> Date: Mon, 19 May 2025 22:46:29 +0800 Subject: [PATCH] feat: add bind_domain and ip_limit res (#8741) --- core/app/api/v2/helper/helper.go | 22 ++++++++++++++++++++++ core/middleware/bind_domain.go | 8 ++------ core/middleware/ip_limit.go | 8 ++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/core/app/api/v2/helper/helper.go b/core/app/api/v2/helper/helper.go index 2430a0e52..4d374f0ac 100644 --- a/core/app/api/v2/helper/helper.go +++ b/core/app/api/v2/helper/helper.go @@ -1,6 +1,8 @@ package helper import ( + "fmt" + "github.com/1Panel-dev/1Panel/core/cmd/server/res" "net/http" "github.com/1Panel-dev/1Panel/core/app/dto" @@ -72,3 +74,23 @@ func ErrResponse(ctx *gin.Context, code int) { ctx.JSON(code, nil) ctx.Abort() } + +func ErrWithHtml(ctx *gin.Context, code int, scope string) { + if code == 444 { + ctx.String(444, "") + ctx.Abort() + return + } + file := fmt.Sprintf("html/%d.html", code) + if code == 200 && scope != "" { + file = fmt.Sprintf("html/200_%s.html", scope) + } + data, err := res.ErrorMsg.ReadFile(file) + if err != nil { + ctx.String(http.StatusInternalServerError, "Internal Server Error") + ctx.Abort() + return + } + ctx.Data(code, "text/html; charset=utf-8", data) + ctx.Abort() +} diff --git a/core/middleware/bind_domain.go b/core/middleware/bind_domain.go index 5ba7f1ed8..1a1288e4d 100644 --- a/core/middleware/bind_domain.go +++ b/core/middleware/bind_domain.go @@ -1,7 +1,6 @@ package middleware import ( - "errors" "strings" "github.com/1Panel-dev/1Panel/core/app/api/v2/helper" @@ -28,11 +27,8 @@ func BindDomain() gin.HandlerFunc { } if domains != status.Value { - if LoadErrCode() != 200 { - helper.ErrResponse(c, LoadErrCode()) - return - } - helper.ErrorWithDetail(c, 311, "ErrInternalServer", errors.New("domain not allowed")) + code := LoadErrCode() + helper.ErrWithHtml(c, code, "err_domain") return } c.Next() diff --git a/core/middleware/ip_limit.go b/core/middleware/ip_limit.go index 880d6c709..7e618481a 100644 --- a/core/middleware/ip_limit.go +++ b/core/middleware/ip_limit.go @@ -1,7 +1,6 @@ package middleware import ( - "errors" "github.com/1Panel-dev/1Panel/core/utils/common" "strings" @@ -33,10 +32,7 @@ func WhiteAllow() gin.HandlerFunc { return } } - if LoadErrCode() != 200 { - helper.ErrResponse(c, LoadErrCode()) - return - } - helper.ErrorWithDetail(c, 310, "ErrInternalServer", errors.New("IP address not allowed")) + code := LoadErrCode() + helper.ErrWithHtml(c, code, "err_ip_limit") } }