diff --git a/Source/EvlWatcher/EvlWatcher/EvlWatcher.cs b/Source/EvlWatcher/EvlWatcher/EvlWatcher.cs index 73d1faf..310c13b 100644 --- a/Source/EvlWatcher/EvlWatcher/EvlWatcher.cs +++ b/Source/EvlWatcher/EvlWatcher/EvlWatcher.cs @@ -331,6 +331,7 @@ private void PushBanList() .Union(_serviceconfiguration.BlacklistAddresses) .Distinct() .Where(address => !IsWhiteListed(address)) + .Where(address => !address.Equals(IPAddress.Any)) .ToList(); _firewallApi.AdjustIPBanList(banList); @@ -503,29 +504,29 @@ private void Run() } } - List blackList = new List(); + List polledTempBansOfThisCycle = new List(); + List polledPermaBansOfThisCycle = new List(); //let the tasks poll which ips they want to have blocked / or permanently banned foreach (LogTask t in _logTasks) { if (t is IPBlockingLogTask ipTask) { - SetPermanentBanInternal(ipTask.GetPermaBanVictims().ToArray()); + List polledTempBansOfThisTask = ipTask.GetTempBanVictims(); + List polledPermaBansOfThisTask = ipTask.GetPermaBanVictims(); - List blockedIPs = ipTask.GetTempBanVictims(); + _logger.Dump($"Polled {t.Name} and got {polledTempBansOfThisTask.Count} temporary and {polledPermaBansOfThisTask.Count()} permanent ban(s)", SeverityLevel.Verbose); - _logger.Dump($"Polled {t.Name} and got {blockedIPs.Count} temporary and {_serviceconfiguration.BlacklistAddresses.Count()} permanent ban(s)", SeverityLevel.Verbose); - - foreach (IPAddress blockedIP in blockedIPs) - if (!blackList.Contains(blockedIP)) - blackList.Add(blockedIP); + polledPermaBansOfThisCycle.AddRange(polledPermaBansOfThisTask.Where(ip => !polledPermaBansOfThisCycle.Contains(ip)).ToList()); + polledTempBansOfThisCycle.AddRange(polledTempBansOfThisTask.Where(ip => !polledTempBansOfThisCycle.Contains(ip)).ToList()); } } _logger.Dump($"\r\n-----Cycle complete, sleeping {_serviceconfiguration.EventLogInterval} s......\r\n", SeverityLevel.Debug); - - _lastPolledTempBans = blackList; + SetPermanentBanInternal(polledPermaBansOfThisCycle.ToArray(), pushBanList: false); + _lastPolledTempBans = polledTempBansOfThisCycle; + PushBanList(); } catch (Exception executionException) @@ -570,12 +571,13 @@ private void Run() } } - private void SetPermanentBanInternal(IPAddress[] addressList) + private void SetPermanentBanInternal(IPAddress[] addressList, bool pushBanList=true) { foreach (IPAddress address in addressList) _serviceconfiguration.AddBlackListAddress(address); - PushBanList(); + if (pushBanList) + PushBanList(); }