aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar bai 2020-07-22 06:33:52 -0400
committerLibravatar bai 2020-07-22 06:33:52 -0400
commitc07c6f7d96ee621cad2522646f25c4deb8e9147d (patch)
tree19a13be13941539ba8e91743c975b30cf7fe1a3b
parentd4b0e27b70f5c7c324edbbaa930197970dfe55c8 (diff)
downloadweabot-c07c6f7d96ee621cad2522646f25c4deb8e9147d.tar.gz
weabot-c07c6f7d96ee621cad2522646f25c4deb8e9147d.tar.xz
weabot-c07c6f7d96ee621cad2522646f25c4deb8e9147d.zip
Reimplementados bans ciegos para ser compatibles con nginx
-rw-r--r--cgi/post.py27
-rw-r--r--cgi/templates/bansconf7
2 files changed, 20 insertions, 14 deletions
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 @@
+<?py for board, ips in bans.iteritems(): ?>
+location /#{board}/ {
+ <?py for ip in ips: ?>
+ deny #{ip};
+ <?py #endfor ?>
+}
+<?py #endfor ?>