diff --git a/backend/app/api/v1/helper/helper.go b/backend/app/api/v1/helper/helper.go index aa4afa8fa..7e5566a29 100644 --- a/backend/app/api/v1/helper/helper.go +++ b/backend/app/api/v1/helper/helper.go @@ -3,6 +3,7 @@ package helper import ( "context" "fmt" + "github.com/1Panel-dev/1Panel/cmd/server/res" "net/http" "strconv" @@ -138,3 +139,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/backend/init/router/router.go b/backend/init/router/router.go index 4de39bf27..750ea65f6 100644 --- a/backend/init/router/router.go +++ b/backend/init/router/router.go @@ -156,6 +156,9 @@ func Routers() *gin.Engine { Router.Use(middleware.DemoHandle()) } + Router.Use(middleware.WhiteAllow()) + Router.Use(middleware.BindDomain()) + Router.NoRoute(func(c *gin.Context) { if checkFrontendPath(c) { toIndexHtml(c) @@ -182,8 +185,7 @@ func Routers() *gin.Engine { setWebStatic(PublicGroup) } PrivateGroup := Router.Group("/api/v1") - PrivateGroup.Use(middleware.WhiteAllow()) - PrivateGroup.Use(middleware.BindDomain()) + PrivateGroup.Use(middleware.GlobalLoading()) for _, router := range rou.RouterGroupApp { router.InitRouter(PrivateGroup) diff --git a/backend/middleware/bind_domain.go b/backend/middleware/bind_domain.go index 8ca06f2ea..ca5342db1 100644 --- a/backend/middleware/bind_domain.go +++ b/backend/middleware/bind_domain.go @@ -1,7 +1,6 @@ package middleware import ( - "errors" "strings" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" @@ -30,11 +29,7 @@ func BindDomain() gin.HandlerFunc { if domains != status.Value { code := LoadErrCode() - if code != 200 { - helper.ErrResponse(c, code) - return - } - helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, errors.New("domain not allowed")) + helper.ErrWithHtml(c, code, "err_domain") return } c.Next() diff --git a/backend/middleware/ip_limit.go b/backend/middleware/ip_limit.go index d396b78ed..c2d2aa740 100644 --- a/backend/middleware/ip_limit.go +++ b/backend/middleware/ip_limit.go @@ -1,7 +1,6 @@ package middleware import ( - "errors" "net" "strings" @@ -36,11 +35,7 @@ func WhiteAllow() gin.HandlerFunc { } } code := LoadErrCode() - if code != 200 { - helper.ErrResponse(c, code) - return - } - helper.ErrorWithDetail(c, constant.CodeErrIP, constant.ErrTypeInternalServer, errors.New("IP address not allowed")) + helper.ErrWithHtml(c, code, "ip_limit") } } diff --git a/cmd/server/res/html/200_err_domain.html b/cmd/server/res/html/200_err_domain.html new file mode 100644 index 000000000..0591abc60 --- /dev/null +++ b/cmd/server/res/html/200_err_domain.html @@ -0,0 +1,55 @@ + + + + + + Access Temporarily Unavailable + + + +
+

Access Temporarily Unavailable

+

The current environment has enabled domain name binding.

+

You can enter the following command in the SSH terminal to reset the binding information:

+

1pctl rest domain

+
+ + diff --git a/cmd/server/res/html/200_err_ip_limit.html b/cmd/server/res/html/200_err_ip_limit.html new file mode 100644 index 000000000..e5e944cbb --- /dev/null +++ b/cmd/server/res/html/200_err_ip_limit.html @@ -0,0 +1,55 @@ + + + + + + Access Temporarily Unavailable + + + +
+

Access Temporarily Unavailable

+

The current environment has enabled authorized IP access.

+

You can enter the following command in the SSH terminal to reset the binding information:

+

1pctl reset ips

+
+ + diff --git a/frontend/src/components/error-message/err_domain.vue b/frontend/src/components/error-message/err_domain.vue deleted file mode 100644 index bf66f0c38..000000000 --- a/frontend/src/components/error-message/err_domain.vue +++ /dev/null @@ -1,55 +0,0 @@ - - - - - diff --git a/frontend/src/components/error-message/err_ip.vue b/frontend/src/components/error-message/err_ip.vue deleted file mode 100644 index 31908f1d0..000000000 --- a/frontend/src/components/error-message/err_ip.vue +++ /dev/null @@ -1,54 +0,0 @@ - - - - - diff --git a/frontend/src/components/error-message/unsafe.vue b/frontend/src/components/error-message/unsafe.vue deleted file mode 100644 index 4eaea371c..000000000 --- a/frontend/src/components/error-message/unsafe.vue +++ /dev/null @@ -1,55 +0,0 @@ - - - - -