From 4ae394f5dfd8d8024df7c8637ffb33891fc346e7 Mon Sep 17 00:00:00 2001 From: z411 Date: Sat, 30 Mar 2019 21:41:18 -0300 Subject: Agregada funciĆ³n de limpieza al cambiar tipo de board --- cgi/framework.py | 9 +++++++++ cgi/manage.py | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'cgi') diff --git a/cgi/framework.py b/cgi/framework.py index 4c89bb7..e827f67 100644 --- a/cgi/framework.py +++ b/cgi/framework.py @@ -56,6 +56,15 @@ def setBoard(dir): return board +def cleanDir(path, ext=None): + if ext: + filelist = [ f for f in os.listdir(path) if f.endswith("." + ext) ] + else: + filelist = os.listdir(path) + + for f in filelist: + os.remove(os.path.join(path, f)) + def addressIsBanned(ip, board): packed_ip = inet_aton(ip) bans = FetchAll("SELECT * FROM `bans` WHERE (`netmask` IS NULL AND `ip` = '"+str(packed_ip)+"') OR (`netmask` IS NOT NULL AND '"+str(packed_ip)+"' & `netmask` = `ip`)") diff --git a/cgi/manage.py b/cgi/manage.py index 71ed647..9ac2006 100644 --- a/cgi/manage.py +++ b/cgi/manage.py @@ -775,8 +775,8 @@ def manage(self, path_split): board['anonymous'] = self.formdata['anonymous'] board['subject'] = self.formdata['subject'] board['message'] = self.formdata['message'] - if board['dir'] != 'anarkia': - board['board_type'] = self.formdata['type'] + switchBoard(self.formdata['type']) + board['board_type'] = self.formdata['type'] board['useid'] = self.formdata['useid'] board['slip'] = self.formdata['slip'] board['countrycode'] = self.formdata['countrycode'] @@ -1828,6 +1828,36 @@ def manage(self, path_split): }) self.output += renderTemplate("manage/" + template_filename, template_values) + +def switchBoard(new_type): + board = Settings._.BOARD + + if new_type == board['board_type']: + return + + kako_dir = os.path.join(Settings.ROOT_DIR, board['dir'], 'kako') + + if new_type == '0': + # Switching to Imageboard + old_res_dir = os.path.join(Settings.ROOT_DIR, board['dir'], 'read') + new_res_dir = os.path.join(Settings.ROOT_DIR, board['dir'], 'res') + + # Delete kako if empty + if os.path.exists(kako_dir) and not os.listdir(kako_dir): + os.rmdir(kako_dir) + elif new_type == '1': + # Switching to Textboard + old_res_dir = os.path.join(Settings.ROOT_DIR, board['dir'], 'res') + new_res_dir = os.path.join(Settings.ROOT_DIR, board['dir'], 'read') + + # Make kako dir + if not os.path.exists(kako_dir): + os.mkdir(kako_dir) + + os.rename(old_res_dir, new_res_dir) + + # Clean res dir + cleanDir(new_res_dir, ext="html") def logAction(staff, action): InsertDb("INSERT INTO `logs` (`timestamp`, `staff`, `action`) VALUES (" + str(timestamp()) + ", '" + _mysql.escape_string(staff) + "\', \'" + _mysql.escape_string(action) + "\')") -- cgit v1.2.1-18-gbd029