36 lines
580 B
Go
36 lines
580 B
Go
package middleware
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"kefu/models"
|
|
"log"
|
|
"strings"
|
|
)
|
|
|
|
//IP白名单
|
|
func SystemIpWhite(c *gin.Context) {
|
|
ip := c.ClientIP()
|
|
|
|
blackList := models.FindConfig("SystemWhiteList")
|
|
strings.ReplaceAll(blackList, "\r\n", "\n")
|
|
list := strings.Split(blackList, "\n")
|
|
exist := false
|
|
for _, word := range list {
|
|
word = strings.Trim(word, " ")
|
|
if word == "" {
|
|
continue
|
|
}
|
|
if ip == word {
|
|
exist = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !exist {
|
|
log.Println("ip whitelist forbidden", ip)
|
|
c.String(403, "403 forbidden")
|
|
c.Abort()
|
|
return
|
|
}
|
|
}
|