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