aboutsummaryrefslogtreecommitdiff
path: root/cgi
diff options
context:
space:
mode:
authorLibravatar z411 2019-03-30 21:41:18 -0300
committerLibravatar z411 2019-03-30 21:41:18 -0300
commit4ae394f5dfd8d8024df7c8637ffb33891fc346e7 (patch)
tree2c8a8f56f50714151864b3aea78ac06ff9863960 /cgi
parentd854378da5648b14c5fb323f254a2b373eb705bb (diff)
downloadweabot-4ae394f5dfd8d8024df7c8637ffb33891fc346e7.tar.gz
weabot-4ae394f5dfd8d8024df7c8637ffb33891fc346e7.tar.xz
weabot-4ae394f5dfd8d8024df7c8637ffb33891fc346e7.zip
Agregada funciĆ³n de limpieza al cambiar tipo de board
Diffstat (limited to 'cgi')
-rw-r--r--cgi/framework.py9
-rw-r--r--cgi/manage.py34
2 files changed, 41 insertions, 2 deletions
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) + "\')")