From 68de71df6c1bc0589dd0495e1e35ed360c682270 Mon Sep 17 00:00:00 2001 From: Tomek Dubrownik Date: Thu, 26 Apr 2012 12:16:36 +0200 Subject: [PATCH] initial public commit --- README | 1 + config.py.dist | 10 ++++ shame.ini | 8 +++ shame.py | 54 +++++++++++++++++ static/base.css | 12 ++++ static/hs.png | Bin 0 -> 2093 bytes static/map.js | 135 ++++++++++++++++++++++++++++++++++++++++++ static/marker.png | Bin 0 -> 5757 bytes static/omgitspins.gif | Bin 0 -> 5330 bytes static/shadow.png | Bin 0 -> 5552 bytes templates/root.html | 12 ++++ 11 files changed, 232 insertions(+) create mode 100644 README create mode 100644 config.py.dist create mode 100644 shame.ini create mode 100644 shame.py create mode 100644 static/base.css create mode 100644 static/hs.png create mode 100644 static/map.js create mode 100644 static/marker.png create mode 100644 static/omgitspins.gif create mode 100644 static/shadow.png create mode 100644 templates/root.html diff --git a/README b/README new file mode 100644 index 0000000..ee1cba5 --- /dev/null +++ b/README @@ -0,0 +1 @@ +Shame/Banany diff --git a/config.py.dist b/config.py.dist new file mode 100644 index 0000000..2889f08 --- /dev/null +++ b/config.py.dist @@ -0,0 +1,10 @@ +port = 9090 +secret_key = 'flasksecretkey' + +limit = 500 + +db = 'fail2sql' +db_user = 'fail2sql' +db_pass = 'password' +db_host = 'localhost' +db_port = 8740 diff --git a/shame.ini b/shame.ini new file mode 100644 index 0000000..3593842 --- /dev/null +++ b/shame.ini @@ -0,0 +1,8 @@ +[uwsgi] +master = 1 +http = 0.0.0.0:8081 +threads = 10 +chdir = /var/www/shame +module = shame +callable = app +debug = true diff --git a/shame.py b/shame.py new file mode 100644 index 0000000..c3a4bc1 --- /dev/null +++ b/shame.py @@ -0,0 +1,54 @@ +from flask import Flask, request, session, g, jsonify, render_template +import MySQLdb as sql +import config + +app = Flask(__name__) +app.secret_key = config.secret_key +app.debug = True + +def sql_connect(): + app.conn = sql.connect(config.db_host, config.db_user, config.db_pass, config.db) + +def sql_execute(query, *a, **kw): + rval = None + try: + rval = g.db.execute(query, *a, **kw) + except (sql.OperationalError, AttributeError): + sql_connect() + make_cursor() + rval = g.db.execute(query, *a, **kw) + finally: + return rval + +@app.before_request +def make_cursor(): + g.db = app.conn.cursor(sql.cursors.DictCursor) + +@app.teardown_request +def close_cursor(exception): + g.db.close() + +@app.route('/shamed') +def home(): + sql_execute('select id, ip, longitude, latitude, geo from f2s_hosts') + points = g.db.fetchmany(config.limit) + return jsonify(points=points) + +@app.route('/shameon/') +def shameon(pointID): + sql_execute('select * from f2s_bans where id = %s order by time desc', (pointID, )) + bans = g.db.fetchall() + for b in bans: + b['time'] = str(b['time']) + return jsonify(bans=bans) + +@app.route('/') +def root(): + return render_template('root.html') + +@app.before_first_request +def initialize(): + sql_connect() + +if __name__ == '__main__': + app.run('0.0.0.0', config.port, debug=True) diff --git a/static/base.css b/static/base.css new file mode 100644 index 0000000..874ef41 --- /dev/null +++ b/static/base.css @@ -0,0 +1,12 @@ +#map { + margin: 0; + min-height: 500px; + width: 100%; + height: 100%; + position: absolute; +} + +body { + margin: 0; + padding: 0; +} diff --git a/static/hs.png b/static/hs.png new file mode 100644 index 0000000000000000000000000000000000000000..40d95d77c468268b2c3adf328f14a727cfea67cf GIT binary patch literal 2093 zcmV+|2-5e7P)002t}1^@s6I8J)%00001b5ch_0Itp) z=>Px#24YJ`L;wH)0002_L%V+f000SaNLh0L00@Er00@EsjZ{Wq00007bV*G`2iyb= z1`j&x+p#7900*r}L_t(|+U=Z6NE=-g$Nza~Y)HsLN!&EiMHM6Ikl0`g>LL(B5f`Cg zNf)*SO@!jEZnBZKbYXSx_*k@Vgn*B&DYzIH7GqKqF`!+<=*ED8FCyl_{T3hnkmfa$ z>3nLE16g^`|IGb4uXE1a3!~9U091Yjenz8_hyak;*;%x+3790O0cS5+frcn3|dbAtdAPB9RC# zmkZ*t-)Y0fTroJpa6gn0-B~_Fc`45wpO074i68}+uMu%{e4#B z_xJbF+uMu7!^84}H8?nkv$Hc!K4)iV7#tidFIe;Q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hYVPMV=Z64zMV`agI=%arLWiP^A_&@x4t1?SYojlMx&AQ zf$*KkO*0ye5R1ja!=fk(YPGuPARQeY1#_+L?rvTaDdewEDA3W-QMA5VtVW>VPoF-arKN?{ z*qNCbs8lLW`YM$QGcz-+#&?17R43QzD&8rHI?@W}Uh@91e1NddfYK{%wnki$twf=M13N>oamG zE+v|aiwiO|G(WxYogRVl5hsX=>tJKEdZ1uNOs*Vm(`rw2VfJ%Z>", + infoWindow = new gm.InfoWindow({content:infoWindowDefaultText}); + function scaleIcon(url, base, zoom) { + var fac = Math.max(Math.min(Math.pow(2, zoom / 2 - 6), 0.25), 0.0625); + return new gm.MarkerImage(url, null, null, + new gm.Point(base.width * fac, base.height * fac), + new gm.Size(base.width * fac * 2, base.height * fac * 2)) + } + function initialize() { + var style = [ + { + featureType: "water", + stylers: [ + { lightness: -97 } + ] + },{ + featureType: "landscape", + stylers: [ + { lightness: -74 }, + { hue: "#55ff00" } + ] + },{ + featureType: "administrative", + elementType: "geometry", + stylers: [ + { saturation: 82 }, + { hue: "#5eff00" }, + { gamma: 0.25 }, + { lightness: -36 }, + { visibility: "on" } + ] + },{ + featureType: "poi", + stylers: [ + { visibility: "off" } + ] + } + ], + options = { + center: hspos, + zoom: 3, + mapTypeId: gm.MapTypeId.ROADMAP, + styles: style + }, + hsimg = new gm.MarkerImage('/static/hs.png', null, null, new gm.Point(9.375, 9.375), + new gm.Size(18.75, 18.75)); + map = new gm.Map(document.getElementById('map'), options); + gm.event.addListener(map, 'zoom_changed', function() { + points.forEach(function(p) { + var img = scaleIcon('/static/marker.png', iconBase, map.getZoom()), + shadow = scaleIcon('/static/shadow.png', shadowBase, map.getZoom()); + p.marker.setIcon(img); + p.marker.setShadow(shadow); + }); + }); + hsmarker = new gm.Marker({ + position: hspos, + map: map, + icon: hsimg, + title: 'Warsaw Hackerspace' + }); + poll = function() { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if(xhr.readyState === 4 && xhr.status === 200) { + refresh(JSON.parse(xhr.responseText).points); + } + } + xhr.open('GET', '/shamed', true); + xhr.send(null); + } + window.setInterval(poll, 90000); + poll(); + } + function showShitForPoint(point) { + var marker = point.marker, + pointID = point.id, + geo = point.geo, + ip = point.ip, + xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() + { + if (xhr.readyState ===4 && xhr.status === 200) + { + if (infoWindowCurrentPoint == pointID) + { + var bans = JSON.parse(xhr.responseText).bans, + content = "
" + ip + "
(" + geo + ")