2022-10-10 13:07:39 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
2022-11-04 02:38:59 +00:00
|
|
|
"github/fthvgb1/wp-go/config"
|
2022-10-10 13:07:39 +00:00
|
|
|
"github/fthvgb1/wp-go/helper"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ValidateServerNames() func(ctx *gin.Context) {
|
2022-11-15 08:36:21 +00:00
|
|
|
serverName := helper.SimpleSliceToMap(config.Conf.Load().TrustServerNames, func(v string) string {
|
2022-10-10 13:07:39 +00:00
|
|
|
return v
|
2022-10-10 13:33:41 +00:00
|
|
|
})
|
2022-10-10 13:07:39 +00:00
|
|
|
return func(c *gin.Context) {
|
|
|
|
if len(serverName) > 0 {
|
|
|
|
if _, ok := serverName[strings.Split(c.Request.Host, ":")[0]]; !ok {
|
|
|
|
c.Status(http.StatusForbidden)
|
|
|
|
c.Abort()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|