From c07c6f7d96ee621cad2522646f25c4deb8e9147d Mon Sep 17 00:00:00 2001 From: bai Date: Wed, 22 Jul 2020 06:33:52 -0400 Subject: Reimplementados bans ciegos para ser compatibles con nginx --- cgi/post.py | 27 +++++++++++++-------------- cgi/templates/bansconf | 7 +++++++ 2 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 cgi/templates/bansconf diff --git a/cgi/post.py b/cgi/post.py index 5e17df1..bcbda67 100644 --- a/cgi/post.py +++ b/cgi/post.py @@ -1081,30 +1081,25 @@ def regenerateAccess(): if not Settings.HTACCESS_GEN: return False - bans = FetchAll("SELECT INET_NTOA(`ip`) AS 'ip', INET_NTOA(`netmask`) AS 'netmask', `boards` FROM `bans` WHERE `blind` = '1'") - listbans = dict() - #listbans_global = list() + bans = FetchAll("SELECT `ipstr`, `boards` FROM `bans` WHERE `blind` = '1'") + listbans = {} boarddirs = FetchAll('SELECT `dir` FROM `boards`') for board in boarddirs: - listbans[board['dir']] = list() + listbans[board['dir']] = [] for ban in bans: - ipmask = ban["ip"] - if ban["netmask"] is not None: - ipmask += '/' + ban["netmask"] - if ban["boards"] != "": boards = pickle.loads(ban["boards"]) for board in boards: - listbans[board].append(ipmask) + listbans[board].append(ban["ipstr"]) else: - #listbans_global.append(ban["ip"]) for board in boarddirs: if board['dir'] not in Settings.EXCLUDE_GLOBAL_BANS: - listbans[board['dir']].append(ipmask) + listbans[board['dir']].append(ban["ipstr"]) # Generate .htaccess for each board + """ TODO: htaccess for board in listbans.keys(): template_values = { 'ips': listbans[board], @@ -1116,13 +1111,17 @@ def regenerateAccess(): try: f.write(page_rendered) finally: - f.close() - + f.close()""" + + page_rendered = renderTemplate('bansconf', {'bans': listbans}) + with open(Settings.ROOT_DIR + "/bans.conf", "w") as f: + f.write(page_rendered) + return True def regenerateKako(): board = Settings._.BOARD - + threads = FetchAll("SELECT * FROM archive WHERE boardid = %s ORDER BY timestamp DESC" % board['id']) page = renderTemplate('kako.html', {'threads': threads}) with open(Settings.ROOT_DIR + board["dir"] + "/kako/index.html", "w") as f: diff --git a/cgi/templates/bansconf b/cgi/templates/bansconf new file mode 100644 index 0000000..07e8afd --- /dev/null +++ b/cgi/templates/bansconf @@ -0,0 +1,7 @@ + +location /#{board}/ { + + deny #{ip}; + +} + -- cgit v1.2.1-18-gbd029