From 4c5c4c953caeeb1cf35535b5b078f77a297a1f5a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 24 Nov 2016 09:24:19 -0500 Subject: [PATCH 1/5] more --- baddiefinder/baddiefinder/__main__.py | 2 +- baddiefinder/baddiefinder/web.py | 29 +++++++++++++++++++++++++++ baddiefinder/requirements.txt | 3 +-- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 baddiefinder/baddiefinder/web.py diff --git a/baddiefinder/baddiefinder/__main__.py b/baddiefinder/baddiefinder/__main__.py index fa92c2f..830d207 100644 --- a/baddiefinder/baddiefinder/__main__.py +++ b/baddiefinder/baddiefinder/__main__.py @@ -17,7 +17,7 @@ def main(): args = ap.parse_args() s = settings.load(args.settings) - fmax = s.get("thresholds", "max_floodfills_per_ip", fallback=5) + fmax = s.get("thresholds", "max_floodfills_per_ip", fallback=3) f = filter.FloodfillFilter(fmax) p = processor.BaddieProcessor([f]) netdb.inspect(p.hook) diff --git a/baddiefinder/baddiefinder/web.py b/baddiefinder/baddiefinder/web.py new file mode 100644 index 0000000..eaa5fe0 --- /dev/null +++ b/baddiefinder/baddiefinder/web.py @@ -0,0 +1,29 @@ +import flask +import io +import netdb + +from . import settings +from . import filter +from . import processor + +app = flask.Flask(__name__) + +@app.route("/baddies.txt") +def baddies(): + s = settings.load('baddies.ini') + fmax = s.get("thresholds", "max_floodfills_per_ip", fallback=3) + f = filter.FloodfillFilter(fmax) + p = processor.BaddieProcessor([f]) + path = s.get("netdb", "directory", fallback=None) + if path: + netdb.inspect(p.hook, path) + else: + netdb.inspect(p.hook) + body = io.BytesIO() + p.write_blocklist(body) + return body + +@app.route("/") +def index(): + return """this server serves a router info blocklist of ip addresses with unreasonably high desnity of i2p routers (right now just floodfills) +""" diff --git a/baddiefinder/requirements.txt b/baddiefinder/requirements.txt index 8273fd3..7e10602 100644 --- a/baddiefinder/requirements.txt +++ b/baddiefinder/requirements.txt @@ -1,2 +1 @@ -python-geoip -python-geoip-geolite2 +flask From 628ba2a0474c8e9934a8157d3e8891430113ec8f Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 24 Nov 2016 09:24:42 -0500 Subject: [PATCH 2/5] more --- baddiefinder/baddiefinder/web.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baddiefinder/baddiefinder/web.py b/baddiefinder/baddiefinder/web.py index eaa5fe0..9677d7d 100644 --- a/baddiefinder/baddiefinder/web.py +++ b/baddiefinder/baddiefinder/web.py @@ -14,7 +14,7 @@ def baddies(): fmax = s.get("thresholds", "max_floodfills_per_ip", fallback=3) f = filter.FloodfillFilter(fmax) p = processor.BaddieProcessor([f]) - path = s.get("netdb", "directory", fallback=None) + path = s.get("netdb", "dir", fallback=None) if path: netdb.inspect(p.hook, path) else: From 45cc9532e05b3aacf297f5949a3c318763a2e724 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 24 Nov 2016 09:25:15 -0500 Subject: [PATCH 3/5] more --- baddiefinder/baddies.ini | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/baddiefinder/baddies.ini b/baddiefinder/baddies.ini index a558c3a..85338b5 100644 --- a/baddiefinder/baddies.ini +++ b/baddiefinder/baddies.ini @@ -1,2 +1,5 @@ [thresholds] -max_floodfills_per_ip = 3 \ No newline at end of file +max_floodfills_per_ip = 3 + +#[netdb] +#dir=/var/lib/i2p/netdb \ No newline at end of file From abbe0fc559b2e7495e56fbad488b65f6c8a5efc3 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 24 Nov 2016 09:26:48 -0500 Subject: [PATCH 4/5] more --- baddiefinder/baddiefinder/web.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/baddiefinder/baddiefinder/web.py b/baddiefinder/baddiefinder/web.py index 9677d7d..a2a6303 100644 --- a/baddiefinder/baddiefinder/web.py +++ b/baddiefinder/baddiefinder/web.py @@ -27,3 +27,7 @@ def baddies(): def index(): return """this server serves a router info blocklist of ip addresses with unreasonably high desnity of i2p routers (right now just floodfills) """ + + +if __name__ == '__main__': + app.run() From 736a5be21a796b1a28d0200ac4cf82dde732dc36 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 24 Nov 2016 09:32:22 -0500 Subject: [PATCH 5/5] update web --- baddiefinder/baddiefinder/web.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/baddiefinder/baddiefinder/web.py b/baddiefinder/baddiefinder/web.py index a2a6303..c299eb9 100644 --- a/baddiefinder/baddiefinder/web.py +++ b/baddiefinder/baddiefinder/web.py @@ -19,9 +19,13 @@ def baddies(): netdb.inspect(p.hook, path) else: netdb.inspect(p.hook) - body = io.BytesIO() + body = io.StringIO() p.write_blocklist(body) - return body + v = body.getvalue() + body.close() + r = flask.Response(v) + r.headers["Content-Type"] = 'text/plain' + return r @app.route("/") def index():