aboutsummaryrefslogtreecommitdiff
path: root/cgi/post.py
diff options
context:
space:
mode:
Diffstat (limited to 'cgi/post.py')
-rw-r--r--cgi/post.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/cgi/post.py b/cgi/post.py
index bcbda67..da2ad47 100644
--- a/cgi/post.py
+++ b/cgi/post.py
@@ -1081,22 +1081,21 @@ def regenerateAccess():
if not Settings.HTACCESS_GEN:
return False
- bans = FetchAll("SELECT `ipstr`, `boards` FROM `bans` WHERE `blind` = '1'")
- listbans = {}
+ bans = FetchAll("SELECT `ipstr`, `boards` FROM `bans` WHERE `blind` = '1' ORDER BY `ipstart` ASC")
- boarddirs = FetchAll('SELECT `dir` FROM `boards`')
- for board in boarddirs:
- listbans[board['dir']] = []
+ boards = FetchAll('SELECT `dir` FROM `boards`')
+ global_boards = [board['dir'] for board in boards if board['dir'] not in Settings.EXCLUDE_GLOBAL_BANS]
+
+ global_bans = []
+ board_bans = {}
for ban in bans:
- if ban["boards"] != "":
+ if ban["boards"]:
boards = pickle.loads(ban["boards"])
for board in boards:
- listbans[board].append(ban["ipstr"])
+ board_bans.setdefault(board, []).append(ban["ipstr"])
else:
- for board in boarddirs:
- if board['dir'] not in Settings.EXCLUDE_GLOBAL_BANS:
- listbans[board['dir']].append(ban["ipstr"])
+ global_bans.append(ban["ipstr"])
# Generate .htaccess for each board
""" TODO: htaccess
@@ -1112,11 +1111,23 @@ def regenerateAccess():
f.write(page_rendered)
finally:
f.close()"""
-
- page_rendered = renderTemplate('bansconf', {'bans': listbans})
- with open(Settings.ROOT_DIR + "/bans.conf", "w") as f:
+
+ template_values = {
+ 'global_boards': global_boards,
+ 'global_bans': global_bans,
+ 'board_bans': board_bans,
+ }
+
+ page_rendered = renderTemplate('bans_geo', template_values)
+ with open(Settings.ROOT_DIR + "/bans_geo.conf", "w") as f:
+ f.write(page_rendered)
+
+ page_rendered = renderTemplate('bans_locations', template_values)
+ with open(Settings.ROOT_DIR + "/bans_locations.conf", "w") as f:
f.write(page_rendered)
+ os.utime(Settings.ROOT_DIR + "/bans.conf", None)
+
return True
def regenerateKako():