加开关中间件网关登录策略-IP限制

This commit is contained in:
TsMask
2023-08-26 17:01:08 +08:00
parent 8b300036cd
commit 9a6684b257

View File

@@ -29,17 +29,29 @@ func ArrowIPAddr(next http.Handler) http.Handler {
next.ServeHTTP(w, r)
return
}
// 开关
switchStr := data["switch"].(string)
if switchStr == "0" {
next.ServeHTTP(w, r)
return
}
ipRange := data["ipRange"].(string)
logintimeRange := data["logintime_range"].(string)
// 检查ip
ips := strings.Split(ipRange, "/")
hasIP := false
for _, ip := range ips {
if ipAddr != ip {
services.ResponseErrorWithJson(w, 502, "网关登录策略-IP限制: "+ipAddr)
return
if ipAddr == ip {
hasIP = true
}
}
if !hasIP {
services.ResponseErrorWithJson(w, 502, "网关登录策略-IP限制: "+ipAddr)
return
}
// 检查开放时间
logintimeRangeArr := strings.Split(logintimeRange, " - ")