mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-11 21:39:00 +00:00
eb0a7b437d
- fix duplicate initialization guard - notification bell for agents - Refactor and clean up dead code - Fixes to pre chat form - Add new column country to users table - Update ratelimit pkg to be generic
39 lines
877 B
Go
39 lines
877 B
Go
package httputil
|
|
|
|
import "net"
|
|
|
|
// IsIPBlocked checks if the given IP address matches any entry in the blocked list.
|
|
// Entries can be individual IPs ("10.0.0.1") or CIDR ranges ("192.168.1.0/24").
|
|
func IsIPBlocked(clientIP string, blockedIPs []string) bool {
|
|
if len(blockedIPs) == 0 {
|
|
return false
|
|
}
|
|
ip := net.ParseIP(clientIP)
|
|
if ip == nil {
|
|
return false
|
|
}
|
|
for _, entry := range blockedIPs {
|
|
if _, network, err := net.ParseCIDR(entry); err == nil {
|
|
if network.Contains(ip) {
|
|
return true
|
|
}
|
|
continue
|
|
}
|
|
if blocked := net.ParseIP(entry); blocked != nil {
|
|
if blocked.Equal(ip) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ValidateIPOrCIDR checks if a string is a valid IP address or CIDR range.
|
|
func ValidateIPOrCIDR(entry string) bool {
|
|
if net.ParseIP(entry) != nil {
|
|
return true
|
|
}
|
|
_, _, err := net.ParseCIDR(entry)
|
|
return err == nil
|
|
}
|