Skip to content

Commit

Permalink
fixes #87
Browse files Browse the repository at this point in the history
  • Loading branch information
devnulli committed Mar 29, 2022
1 parent dafb7b0 commit bf03e4d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions Source/EvlWatcher/EvlWatcher/EvlWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -503,29 +504,29 @@ private void Run()
}
}

List<IPAddress> blackList = new List<IPAddress>();
List<IPAddress> polledTempBansOfThisCycle = new List<IPAddress>();
List<IPAddress> polledPermaBansOfThisCycle = new List<IPAddress>();

//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<IPAddress> polledTempBansOfThisTask = ipTask.GetTempBanVictims();
List<IPAddress> polledPermaBansOfThisTask = ipTask.GetPermaBanVictims();

List<IPAddress> 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)
Expand Down Expand Up @@ -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();
}


Expand Down

0 comments on commit bf03e4d

Please sign in to comment.