Skip to content

Commit 658db55

Browse files
feat: add bind_domain and ip_limit res (#8741)
1 parent 1336b93 commit 658db55

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

core/app/api/v2/helper/helper.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package helper
22

33
import (
4+
"fmt"
5+
"github.com/1Panel-dev/1Panel/core/cmd/server/res"
46
"net/http"
57

68
"github.com/1Panel-dev/1Panel/core/app/dto"
@@ -72,3 +74,23 @@ func ErrResponse(ctx *gin.Context, code int) {
7274
ctx.JSON(code, nil)
7375
ctx.Abort()
7476
}
77+
78+
func ErrWithHtml(ctx *gin.Context, code int, scope string) {
79+
if code == 444 {
80+
ctx.String(444, "")
81+
ctx.Abort()
82+
return
83+
}
84+
file := fmt.Sprintf("html/%d.html", code)
85+
if code == 200 && scope != "" {
86+
file = fmt.Sprintf("html/200_%s.html", scope)
87+
}
88+
data, err := res.ErrorMsg.ReadFile(file)
89+
if err != nil {
90+
ctx.String(http.StatusInternalServerError, "Internal Server Error")
91+
ctx.Abort()
92+
return
93+
}
94+
ctx.Data(code, "text/html; charset=utf-8", data)
95+
ctx.Abort()
96+
}

core/middleware/bind_domain.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package middleware
22

33
import (
4-
"errors"
54
"strings"
65

76
"github.com/1Panel-dev/1Panel/core/app/api/v2/helper"
@@ -28,11 +27,8 @@ func BindDomain() gin.HandlerFunc {
2827
}
2928

3029
if domains != status.Value {
31-
if LoadErrCode() != 200 {
32-
helper.ErrResponse(c, LoadErrCode())
33-
return
34-
}
35-
helper.ErrorWithDetail(c, 311, "ErrInternalServer", errors.New("domain not allowed"))
30+
code := LoadErrCode()
31+
helper.ErrWithHtml(c, code, "err_domain")
3632
return
3733
}
3834
c.Next()

core/middleware/ip_limit.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package middleware
22

33
import (
4-
"errors"
54
"github.com/1Panel-dev/1Panel/core/utils/common"
65
"strings"
76

@@ -33,10 +32,7 @@ func WhiteAllow() gin.HandlerFunc {
3332
return
3433
}
3534
}
36-
if LoadErrCode() != 200 {
37-
helper.ErrResponse(c, LoadErrCode())
38-
return
39-
}
40-
helper.ErrorWithDetail(c, 310, "ErrInternalServer", errors.New("IP address not allowed"))
35+
code := LoadErrCode()
36+
helper.ErrWithHtml(c, code, "err_ip_limit")
4137
}
4238
}

0 commit comments

Comments
 (0)