From e2a449a7bc3f1e3742ef1758b18dc5cfa973f45f Mon Sep 17 00:00:00 2001 From: Toby Chui Date: Tue, 30 Apr 2024 13:39:48 +0800 Subject: [PATCH] Update blacklist.go Fixed blacklist CIDR not working bug --- src/mod/access/blacklist.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/mod/access/blacklist.go b/src/mod/access/blacklist.go index ec243ae..7daab35 100644 --- a/src/mod/access/blacklist.go +++ b/src/mod/access/blacklist.go @@ -2,6 +2,8 @@ package access import ( "strings" + + "imuslab.com/zoraxy/mod/netutils" ) /* @@ -71,5 +73,22 @@ func (s *AccessRule) GetAllBlacklistedIp() []string { func (s *AccessRule) IsIPBlacklisted(ipAddr string) bool { IPBlacklist := *s.BlackListIP _, ok := IPBlacklist[ipAddr] - return ok + if ok { + return true + } + + //Check for CIDR + for ipOrCIDR, _ := range IPBlacklist { + wildcardMatch := netutils.MatchIpWildcard(ipAddr, ipOrCIDR) + if wildcardMatch { + return true + } + + cidrMatch := netutils.MatchIpCIDR(ipAddr, ipOrCIDR) + if cidrMatch { + return true + } + } + + return false }