private void UpdateWhileListPattern(WCF.IEvlWatcherService service) { List <string> entries = new List <string>(service.GetWhiteListEntries()); List <string> toAdd = new List <string>(); List <string> toRemove = new List <string>(); foreach (string s in entries) { if (!_whiteListPattern.Contains(s)) { toAdd.Add(s); } } foreach (string s in _whiteListPattern) { if (!entries.Contains(s)) { toRemove.Add(s); } } foreach (string s in toAdd) { Application.Current.Dispatcher.Invoke(new Action(() => _whiteListPattern.Add(s))); } foreach (string s in toRemove) { Application.Current.Dispatcher.Invoke(new Action(() => _whiteListPattern.Remove(s))); } }
private void RemovePermanentIPBan(IPAddress a) { lock (syncObject) { ChannelFactory <WCF.IEvlWatcherService> f = new ChannelFactory <WCF.IEvlWatcherService>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/EvlWatcher")); WCF.IEvlWatcherService service = f.CreateChannel(); service.ClearPermanentBan(a); } }
private void RemoveWhiteListEntry(string s) { lock (syncObject) { ChannelFactory <WCF.IEvlWatcherService> f = new ChannelFactory <WCF.IEvlWatcherService>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/EvlWatcher")); WCF.IEvlWatcherService service = f.CreateChannel(); service.RemoveWhiteListEntry(s); } }
private void UpdateIPLists(WCF.IEvlWatcherService service) { List <IPAddress> ips = new List <IPAddress>(service.GetTemporarilyBannedIPs()); List <IPAddress> toAdd = new List <IPAddress>(); List <IPAddress> toRemove = new List <IPAddress>(); foreach (IPAddress i in ips) { if (!_temporarilyBannedIps.Contains(i)) { toAdd.Add(i); } } foreach (IPAddress i in _temporarilyBannedIps) { if (!ips.Contains(i)) { toRemove.Add(i); } } foreach (IPAddress i in toAdd) { Application.Current.Dispatcher.Invoke(new Action(() => _temporarilyBannedIps.Add(i))); } foreach (IPAddress i in toRemove) { Application.Current.Dispatcher.Invoke(new Action(() => _temporarilyBannedIps.Remove(i))); } ips = new List <IPAddress>(service.GetPermanentlyBannedIPs()); toAdd = new List <IPAddress>(); toRemove = new List <IPAddress>(); foreach (IPAddress i in ips) { if (!_permanentlyBannedIps.Contains(i)) { toAdd.Add(i); } } foreach (IPAddress i in _permanentlyBannedIps) { if (!ips.Contains(i)) { toRemove.Add(i); } } foreach (IPAddress i in toAdd) { Application.Current.Dispatcher.Invoke(new Action(() => _permanentlyBannedIps.Add(i))); } foreach (IPAddress i in toRemove) { Application.Current.Dispatcher.Invoke(new Action(() => _permanentlyBannedIps.Remove(i))); } }
private void Run() { while (_run) { lock (syncObject) { //do not update in design mode bool running = false; try { ChannelFactory <WCF.IEvlWatcherService> f = new ChannelFactory <WCF.IEvlWatcherService>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/EvlWatcher")); WCF.IEvlWatcherService service = f.CreateChannel(); running = service.GetIsRunning(); if (!running) { continue; } UpdateIPLists(service); UpdateWhileListPattern(service); f.Close(); } catch (EndpointNotFoundException) { //service seems not to be running } catch (TimeoutException) { // same here.. well, would be nice if exception filters would have been invented by now... } finally { this.IsRunning = running; } } try { System.Threading.Thread.Sleep(1000); } catch (ThreadInterruptedException) { } } }
private void Run() { while (_run) { lock (syncObject) { //do not update in design mode bool running = false; try { ChannelFactory <WCF.IEvlWatcherService> f = new ChannelFactory <WCF.IEvlWatcherService>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/EvlWatcher")); WCF.IEvlWatcherService service = f.CreateChannel(); running = service.GetIsRunning(); if (!running) { continue; } UpdateIPLists(service); UpdateWhileListPattern(service); int lt = service.GetTaskProperty("BlockRDPBruters", "LockTime"); int tf = service.GetTaskProperty("BlockRDPBruters", "TimeFrame"); int tc = service.GetTaskProperty("BlockRDPBruters", "TriggerCount"); int pb = service.GetTaskProperty("BlockRDPBruters", "PermaBanCount"); if (lt != _lockTime) { LockTime = lt; } if (tf != _timeFrame) { TimeFrame = tf; } if (tc != _triggerCount) { TriggerCount = tc; } if (pb != _permaBanTrigger) { PermaBanCount = pb; } f.Close(); } catch (EndpointNotFoundException) { //service seems not to be running } catch (TimeoutException) { // same here.. well, would be nice if exception filters would have been invented by now... } finally { this.IsRunning = running; } } try { System.Threading.Thread.Sleep(1000); } catch (ThreadInterruptedException) { } } }