aboutsummaryrefslogtreecommitdiff
path: root/host/secret_sauce.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2017-03-24 14:08:44 +0100
committerjaseg <git@jaseg.net>2017-03-24 14:12:31 +0100
commitb0b2e985a3f35962ed2f4d639d756862fcdc5168 (patch)
tree38d41c8a36d8b0f673e1b6b5cefc4d397608f938 /host/secret_sauce.py
parent7dc09a38bbed26ae188bfafc72b803752501f00a (diff)
downloadmatelight-master.tar.gz
matelight-master.tar.bz2
matelight-master.zip
Add LICENSEHEADmaster
Diffstat (limited to 'host/secret_sauce.py')
-rw-r--r--host/secret_sauce.py56
1 files changed, 0 insertions, 56 deletions
diff --git a/host/secret_sauce.py b/host/secret_sauce.py
deleted file mode 100644
index 3682b0e..0000000
--- a/host/secret_sauce.py
+++ /dev/null
@@ -1,56 +0,0 @@
-
-from collections import defaultdict
-import signal
-
-
-RATELIMIT_THRESHOLD = 20
-GRAYLIST_LENGTH = 8
-
-class SpamError(ValueError):
- def __str__(self):
- return ' '.join(self.args)
-
-
-def loadlist(fn):
- try:
- with open(fn) as f:
- return [ l for l in ( l.strip() for l in f.readlines() if not l.startswith('#')) if l ]
- except:
- return []
-
-greenlist = set()
-
-graylist = []
-def do_graylist(msg):
- global graylist
- graylist = [msg] + graylist[:GRAYLIST_LENGTH-1]
-
-blacklist = loadlist('blacklist')
-badwords = loadlist('badwords')
-def signal_handler(_signum, _frame):
- global blacklist, badwords
- blacklist = load_blacklist()
- badwords = load_badwords()
-signal.signal(signal.SIGHUP, signal_handler)
-
-ratelimitdict = defaultdict(lambda: 0)
-def empty_ratelimit(_signum, _frame):
- global ratelimitdict
- ratelimitdict = defaultdict(lambda: 0)
-signal.signal(signal.SIGALRM, empty_ratelimit)
-signal.setitimer(signal.ITIMER_REAL, 60)
-
-def check_spam(addr, data):
- ratelimitdict[addr] += 1
- try:
- if ratelimitdict[addr] > RATELIMIT_THRESHOLD:
- raise SpamError('rate-limit')
- if any(word in data.lower() for word in badwords):
- raise SpamError('badwords filter')
- if addr not in greenlist and data in graylist:
- raise SpamError('graylist')
- except SpamError as err:
- do_graylist(data)
- blacklist.append(addr)
- raise err
- greenlist.add(addr)