2023-05-19 13:47:46 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
2023-06-01 02:38:11 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/repo"
|
2023-05-19 13:47:46 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BindDomain() gin.HandlerFunc {
|
|
|
|
return func(c *gin.Context) {
|
2023-06-01 02:38:11 +00:00
|
|
|
settingRepo := repo.NewISettingRepo()
|
|
|
|
status, err := settingRepo.Get(settingRepo.WithByKey("BindDomain"))
|
|
|
|
if err != nil {
|
2023-06-25 03:50:13 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
2023-06-01 02:38:11 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(status.Value) == 0 {
|
2023-05-19 13:47:46 +00:00
|
|
|
c.Next()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
domains := c.Request.Host
|
|
|
|
parts := strings.Split(c.Request.Host, ":")
|
|
|
|
if len(parts) > 0 {
|
|
|
|
domains = parts[0]
|
|
|
|
}
|
|
|
|
|
2023-06-01 02:38:11 +00:00
|
|
|
if domains != status.Value {
|
2024-11-13 06:44:00 +00:00
|
|
|
code := LoadErrCode()
|
2024-12-10 03:58:32 +00:00
|
|
|
helper.ErrWithHtml(c, code, "err_domain")
|
2023-05-19 13:47:46 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|