feat: add bind_domain and ip_limit res (#8741)

This commit is contained in:
CityFun
2025-05-19 22:46:29 +08:00
committed by GitHub
parent 1336b93efa
commit 658db55d91
3 changed files with 26 additions and 12 deletions
+22
View File
@@ -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()
}
+2 -6
View File
@@ -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()
+2 -6
View File
@@ -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")
}
}