mirror of http://git.simp.i2p/simp/PyLink.git
cleanup regex_filter
parent
e777ef092f
commit
bec8486fbc
|
@ -1,10 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Regex Filter Plugin for PyLink
|
Regex Filter Plugin for PyLink
|
||||||
Comprehensive message filtering with Perl regex backend and flood protection
|
Comprehensive message filtering with PCRE2 and flood protection
|
||||||
Author: Anon
|
|
||||||
License: BSD 2-Clause
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -65,7 +62,7 @@ def _ensure_directories():
|
||||||
blacklist_path = Path(config['blacklist_file'])
|
blacklist_path = Path(config['blacklist_file'])
|
||||||
if not blacklist_path.exists():
|
if not blacklist_path.exists():
|
||||||
with open(blacklist_path, 'w') as f:
|
with open(blacklist_path, 'w') as f:
|
||||||
f.write("# Regex Blacklist Patterns - One Perl regex per line\n")
|
f.write("# Regex Blacklist Patterns - One regex per line\n")
|
||||||
f.write("# Test all patterns thoroughly before deploying\n")
|
f.write("# Test all patterns thoroughly before deploying\n")
|
||||||
f.write("# Examples (commented out by default):\n")
|
f.write("# Examples (commented out by default):\n")
|
||||||
f.write("# \\bhttps?://(?:bit\\.ly|tinyurl\\.com|t\\.co)/\\w+\\b\n")
|
f.write("# \\bhttps?://(?:bit\\.ly|tinyurl\\.com|t\\.co)/\\w+\\b\n")
|
||||||
|
@ -183,7 +180,7 @@ def _check_flood_protection(source, content):
|
||||||
return False, ""
|
return False, ""
|
||||||
|
|
||||||
def _run_regex(content):
|
def _run_regex(content):
|
||||||
"""Call Perl script to filter content"""
|
"""Filter content using jit compiled pattern"""
|
||||||
for p in Cr.pattern:
|
for p in Cr.pattern:
|
||||||
try:
|
try:
|
||||||
matched = p.match(content)
|
matched = p.match(content)
|
||||||
|
@ -213,7 +210,7 @@ def _should_filter_content(source, target, content, network_name="unknown"):
|
||||||
if is_flood:
|
if is_flood:
|
||||||
return True, flood_reason
|
return True, flood_reason
|
||||||
|
|
||||||
# Check content with Perl filter
|
# Check content with filter
|
||||||
is_blocked, block_reason = _run_regex(content)
|
is_blocked, block_reason = _run_regex(content)
|
||||||
if is_blocked:
|
if is_blocked:
|
||||||
return True, block_reason
|
return True, block_reason
|
||||||
|
|
Loading…
Reference in New Issue