/// <summary> /// Pushes the current ban list down into the system API /// </summary> private void PushBanList() { lock (_syncObject) { List <IPAddress> banList = _lastPolledTempBans .Union(_serviceconfiguration.BlacklistAddresses) .Distinct() .Where(address => !IsWhiteListed(address)) .ToList(); _firewallApi.AdjustIPBanList(banList); foreach (IPAddress ip in _lastBannedIPs.Where(ip => !banList.Contains(ip))) { _logger.Dump($"Removed {ip} from the ban list", SeverityLevel.Info); } foreach (IPAddress ip in banList.Where(ip => !_lastBannedIPs.Contains(ip))) { _logger.Dump($"Banned {ip}", SeverityLevel.Info); } _lastBannedIPs = banList; _logger.Dump($"Pushed {banList.Count} IPs down to the firewall for banning.", SeverityLevel.Debug); } }
/// <summary> /// Pushes the current ban list down into the system API /// </summary> private void PushBanList() { lock (_syncObject) { List <IPAddress> banList = new List <IPAddress>(); if (_lastPolledTempBans != null) { foreach (IPAddress a in _lastPolledTempBans) { if (!banList.Contains(a)) { banList.Add(a); } } } if (_permaBannedIPs != null) { foreach (IPAddress p in _permaBannedIPs) { if (!banList.Contains(p)) { banList.Add(p); } } } List <IPAddress> unbanned = new List <IPAddress>(); foreach (IPAddress i in banList) { foreach (string pattern in _whiteListPatterns) { if (IsPatternMatch(i, pattern) && !unbanned.Contains(i)) { unbanned.Add(i); } } } foreach (IPAddress u in unbanned) { banList.Remove(u); } FirewallAPI.AdjustIPBanList(banList); foreach (IPAddress ip in _lastBannedIPs) { if (!banList.Contains(ip)) { Dump($"Removed {ip} from the ban list", EventLogEntryType.Information); } } foreach (IPAddress ip in banList) { if (!_lastBannedIPs.Contains(ip)) { Dump($"Banned {ip}", EventLogEntryType.Information); } } _lastBannedIPs = banList; } }