mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2024-12-12 11:55:08 +08:00
38 lines
896 B
Go
38 lines
896 B
Go
package middleware
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
"github.com/1Panel-dev/1Panel/backend/app/repo"
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func BindDomain() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
settingRepo := repo.NewISettingRepo()
|
|
status, err := settingRepo.Get(settingRepo.WithByKey("BindDomain"))
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
if len(status.Value) == 0 {
|
|
c.Next()
|
|
return
|
|
}
|
|
domains := c.Request.Host
|
|
parts := strings.Split(c.Request.Host, ":")
|
|
if len(parts) > 0 {
|
|
domains = parts[0]
|
|
}
|
|
|
|
if domains != status.Value {
|
|
helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, errors.New("domain not allowed"))
|
|
return
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|