aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 ?>