Browse Source

update logic

pull/3/head
Jeff Becker 8 years ago
parent
commit
fb77e988e5
  1. 9
      baddie-detector/baddiefinder/filter.py
  2. 5
      baddie-detector/baddiefinder/processor.py

9
baddie-detector/baddiefinder/filter.py

@ -7,7 +7,7 @@ class Filter: @@ -7,7 +7,7 @@ class Filter:
def process(self, info):
"""
process an info and return True if it should be added to blocklist
process an info and return a string representation of a reason to add to blocklist
any other return value will cause this info to NOT be added to blocklist
"""
@ -22,11 +22,12 @@ class FloodfillFilter(Filter): @@ -22,11 +22,12 @@ class FloodfillFilter(Filter):
def process(self, info):
caps = util.getcaps(info)
if not caps:
return False
return
if b'f' not in caps:
return False
return
h = util.getaddress(info)
if h not in self._floodfills:
self._floodfills[h] = 0
self._floodfills[h] += 1
return self._floodfills[h] > self.fmax
if self._floodfills[h] > self.fmax:
return '{} > {} floodfills per ip'.format(self._floodfills[h], self.fmax)

5
baddie-detector/baddiefinder/processor.py

@ -12,8 +12,9 @@ class BaddieProcessor: @@ -12,8 +12,9 @@ class BaddieProcessor:
def hook(self, entry):
now = datetime.datetime.now()
for f in self._filters:
if f.process(entry) is True:
self.add_baddie(entry, 'detected by {} on {}'.format(f.name, now.strftime("%c").replace(":",'-')))
reason = f.process(entry)
if reason is not None:
self.add_baddie(entry, 'detected by {} on {} ({})'.format(f.name, now.strftime("%c").replace(":",'-'), reason))
def add_baddie(self, entry, reason):
addr = util.getaddress(entry).decode('ascii')

Loading…
Cancel
Save