From b09e855283b8521caa35e1aa0762cf8e986559d4 Mon Sep 17 00:00:00 2001 From: neptune Date: Fri, 25 Nov 2022 17:59:09 -0300 Subject: Actualizado repo --- cgi/formatting.py | 54 +++++++++++++--------- cgi/framework.py | 10 ++++ cgi/manage.py | 90 ++++++++++++++++-------------------- cgi/oekaki.py | 2 +- cgi/post.py | 88 ++++++++++++++++++++++------------- cgi/templates/board.html | 6 +-- cgi/templates/board.jp.html | 6 +-- cgi/templates/home.html | 2 + cgi/templates/mobile/board.html | 12 ++--- cgi/templates/mobile/txt_thread.html | 2 +- cgi/templates/paint.html | 8 ++-- cgi/weabot.py | 51 ++++++++++---------- 12 files changed, 180 insertions(+), 151 deletions(-) (limited to 'cgi') diff --git a/cgi/formatting.py b/cgi/formatting.py index 97f44a6..33495a3 100644 --- a/cgi/formatting.py +++ b/cgi/formatting.py @@ -317,12 +317,23 @@ def close_html(message): """ Old retarded version of sanitize_html, it just closes open tags. """ - import BeautifulSoup + #import BeautifulSoup - message = message.encode('utf-8') - soup = BeautifulSoup.BeautifulSoup(message) + #message = message.encode('utf-8') + #soup = BeautifulSoup.BeautifulSoup(message) + + #return str(soup).replace(' ', '').encode('utf-8') - return str(soup).replace(' ', '').encode('utf-8') + try: + l = message.rindex('<') + except ValueError: + return message + test = message[l:] + try: + r = test.rindex('>') + return message + except ValueError: + return message[:l] def sanitize_html(message, decode=True): @@ -375,27 +386,26 @@ def checkWordfilters(message, ip, board): if wordfilter["boards"]: boards = str2boards(wordfilter["boards"]) if not wordfilter["boards"] or board in boards: - if wordfilter['action'] == '0': + if wordfilter['action'] == 0: if not re.search(wordfilter['from'], message, re.DOTALL | re.IGNORECASE) is None: raise UserError(wordfilter['reason']) - elif wordfilter['action'] == '1': + elif wordfilter['action'] == 1: message = re.compile(wordfilter['from'], re.DOTALL | re.IGNORECASE).sub( wordfilter['to'], message) - elif wordfilter['action'] == '2': + elif wordfilter['action'] == 2: # Ban if not re.search(wordfilter['from'], message, re.DOTALL | re.IGNORECASE) is None: - if wordfilter['seconds'] != '0': - until = str(timestamp() + int(wordfilter['seconds'])) + if wordfilter['seconds']: + until = timestamp() + int(wordfilter['seconds']) else: - until = '0' + until = 0 - InsertDb("INSERT INTO `bans` (`ip`, `boards`, `added`, `until`, `staff`, `reason`, `note`, `blind`) VALUES (" + - "INET6_ATON('" + str(ip) + "'), '" + _mysql.escape_string(wordfilter['boards']) + - "', " + str(timestamp()) + ", " + until + ", 'System', '" + _mysql.escape_string(wordfilter['reason']) + - "', 'Word Auto-ban', '"+_mysql.escape_string(wordfilter['blind'])+"')") + sql_query = "INSERT INTO `bans` (`ipstart`, `ipend`, `ipstr`, `boards`, `added`, `until`, `staff`, `reason`, `note`, `blind`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" + sql_params = (ip, ip, ip, wordfilter['boards'], timestamp(), until, "System", wordfilter['reason'], "Filter auto-ban", wordfilter['blind']) + InsertDb(sql_query, sql_params) regenerateAccess() raise UserError(wordfilter['reason']) - elif wordfilter['action'] == '3': + elif wordfilter['action'] == 3: if not re.search(wordfilter['from'], message, re.DOTALL | re.IGNORECASE) is None: raise UserError('%s' % (wordfilter['redirect_time'], wordfilter['redirect_url'], wordfilter['reason'])) return message @@ -426,18 +436,18 @@ def checkNamefilters(name, tripcode, ip, board): if match: # do action - if namefilter['action'] == '0': + if namefilter['action'] == 0: raise UserError(namefilter['reason']) - elif namefilter['action'] == '1': + elif namefilter['action'] == 1: name = namefilter['to'] tripcode = '' return name, tripcode - elif namefilter['action'] == '2': + elif namefilter['action'] == 2: # Ban - if namefilter['seconds'] != '0': - until = str(timestamp() + int(namefilter['seconds'])) + if namefilter['seconds']: + until = timestamp() + int(namefilter['seconds']) else: - until = '0' + until = 0 InsertDb("INSERT INTO `bans` (`ip`, `boards`, `added`, `until`, `staff`, `reason`, `note`, `blind`) VALUES (" + "'" + _mysql.escape_string(ip) + "', '" + _mysql.escape_string(namefilter['boards']) + @@ -445,6 +455,6 @@ def checkNamefilters(name, tripcode, ip, board): "', 'Name Auto-ban', '"+_mysql.escape_string(namefilter['blind'])+"')") regenerateAccess() raise UserError(namefilter['reason']) - elif namefilter['action'] == '3': + elif namefilter['action'] == 3: raise UserError('%s' % (namefilter['redirect_time'], namefilter['redirect_url'], namefilter['reason'])) return name, tripcode diff --git a/cgi/framework.py b/cgi/framework.py index 38ba2ad..1a2d78e 100644 --- a/cgi/framework.py +++ b/cgi/framework.py @@ -128,6 +128,16 @@ def getCountry(ip): return "??" +def clearCache(): + if Settings._.CONN: + Settings._.CONN.close() + Settings._.CONN = None + + Settings._.BOARD = None + Settings._.IS_TOR = None + Settings._.HOST = None + + def getHost(ip): if Settings._.HOST is None: try: diff --git a/cgi/manage.py b/cgi/manage.py index 02eaf41..93a9921 100644 --- a/cgi/manage.py +++ b/cgi/manage.py @@ -274,23 +274,18 @@ def manage(self, path_split): if not moderator: return - try: - action_taken = True - member = FetchOne( - 'SELECT `username` FROM `staff` WHERE `id` = ' + _mysql.escape_string(path_split[4]) + ' LIMIT 1') - if member: - UpdateDb('DELETE FROM `staff` WHERE `id` = ' + - _mysql.escape_string(path_split[4]) + ' LIMIT 1') - message = 'Staff member deleted.' - template_filename = "message.html" - logAction(staff_account['username'], _( - 'Deleted staff account for %s') % member['username']) - else: - message = _( - 'Unable to locate a staff account with that ID.') - template_filename = "message.html" - except: - pass + action_taken = True + member = FetchOne('SELECT `username` FROM `staff` WHERE `id` = %s LIMIT 1', (path_split[4],)) + if member: + UpdateDb('DELETE FROM `staff` WHERE `id` = %s LIMIT 1', (path_split[4],)) + message = 'Staff member deleted.' + template_filename = "message.html" + logAction(staff_account['username'], _( + 'Deleted staff account for %s') % member['username']) + else: + message = _( + 'Unable to locate a staff account with that ID.') + template_filename = "message.html" if not action_taken: staff = FetchAll('SELECT * FROM `staff` ORDER BY `rights`') @@ -353,7 +348,7 @@ def manage(self, path_split): if imageonly: message = 'Archivo de post /%s/%s eliminado.' % ( board['dir'], post['id']) - elif permanently or post["parentid"] == '0': + elif permanently or post["parentid"] == 0: message = 'Post /%s/%s eliminado permanentemente.' % ( board['dir'], post['id']) else: @@ -384,7 +379,7 @@ def manage(self, path_split): message = _('Post is not a thread opener.') template_filename = "message.html" else: - if not post['locked']: + if post['locked'] == 0: # Cerrar si esta abierto setLocked = 1 else: @@ -392,7 +387,7 @@ def manage(self, path_split): setLocked = 0 UpdateDb("UPDATE `posts` SET `locked` = %s WHERE `boardid` = %s AND `id` = %s LIMIT 1", - (setLocked, board["id"], postid)) + (setLocked, board["id"], post["id"])) threadUpdated(postid) if setLocked == 1: message = _('Thread successfully closed.') @@ -732,7 +727,7 @@ def manage(self, path_split): else: message = _('Ban successfully placed.') action = 'Banned ' + ip - if until != '0': + if until != 0: action += ' until ' + \ formatTimestamp(until) else: @@ -997,16 +992,16 @@ def manage(self, path_split): if path_split[4] == 'restore': board = setBoard(path_split[5]) - post = FetchOne('SELECT `parentid` FROM `posts` WHERE `boardid` = ' + - board['id'] + ' AND `id` = \'' + _mysql.escape_string(path_split[6]) + '\' LIMIT 1') + post = FetchOne('SELECT `parentid` FROM `posts` WHERE `boardid` = %s AND `id` = %s LIMIT 1', + (board['id'], path_split[6])) if not post: message = _( 'Unable to locate a post with that ID.') + '
' template_filename = "message.html" else: - UpdateDb('UPDATE `posts` SET `IS_DELETED` = 0 WHERE `boardid` = ' + - board['id'] + ' AND `id` = \'' + _mysql.escape_string(path_split[6]) + '\' LIMIT 1') - if post['parentid'] != '0': + UpdateDb('UPDATE `posts` SET `IS_DELETED` = 0 WHERE `boardid` = %s AND `id` = %s LIMIT 1', + (board['id'], path_split[6])) + if post['parentid'] != 0: threadUpdated(post['parentid']) else: regenerateFrontPages() @@ -1485,8 +1480,7 @@ def manage(self, path_split): elif filter_action == 1: # Change to if len(self.formdata["changeto"]) > 0: - filter_to = _mysql.escape_string( - self.formdata["changeto"]) + filter_to = self.formdata["changeto"] sql_query = "INSERT INTO `filters` (`id`, `boards`, `type`, `action`, `from`, `from_trip`, `reason`, `to`, `added`, `staff`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" sql_params = (edit_id, where, filter_type, filter_action, filter_from, filter_tripcode, filter_reason, filter_to, timestamp(), staff_account['username']) else: @@ -1495,27 +1489,24 @@ def manage(self, path_split): return elif filter_action == 2: # Ban - filter_seconds = '0' + filter_seconds = 0 if len(self.formdata["seconds"]) > 0: - filter_seconds = _mysql.escape_string( - self.formdata["seconds"]) - if "blind" in self.formdata and self.formdata["blind"] == '1': - filter_blind = '1' + filter_seconds = int(self.formdata["seconds"]) + if "blind" in self.formdata and self.formdata["blind"] == 1: + filter_blind = 1 else: - filter_blind = '2' + filter_blind = 2 - sql_query = "INSERT INTO `filters` (`id`, `boards`, `type`, `action`, `from`, `from_trip`, `reason`, `seconds`, `blind`, `added`, `staff`) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" % \ - (edit_id, where, str(filter_type), str(filter_action), filter_from, filter_tripcode, filter_reason, - filter_seconds, filter_blind, str(timestamp()), _mysql.escape_string(staff_account['username'])) + sql_query = "INSERT INTO `filters` (`id`, `boards`, `type`, `action`, `from`, `from_trip`, `reason`, `seconds`, `blind`, `added`, `staff`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" + sql_params = (edit_id, where, filter_type, filter_action, filter_from, filter_tripcode, filter_reason, + filter_seconds, filter_blind, timestamp(), staff_account['username']) elif filter_action == 3: # Redirect URL if len(self.formdata['redirect_url']) > 0: - redirect_url = _mysql.escape_string( - self.formdata['redirect_url']) + redirect_url = self.formdata['redirect_url'] redirect_time = 0 try: - redirect_time = int( - self.formdata['redirect_time']) + redirect_time = int(self.formdata['redirect_time']) except: pass else: @@ -1523,20 +1514,17 @@ def manage(self, path_split): _("You must enter a URL to redirect to.")) return - sql_query = "INSERT INTO `filters` (`id`, `boards`, `type`, `action`, `from`, `from_trip`, `reason`, `redirect_url`, `redirect_time`, `added`, `staff`) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" % \ - (edit_id, where, str(filter_type), str(filter_action), filter_from, filter_tripcode, filter_reason, redirect_url, str( - redirect_time), str(timestamp()), _mysql.escape_string(staff_account['username'])) + sql_query = "INSERT INTO `filters` (`id`, `boards`, `type`, `action`, `from`, `from_trip`, `reason`, `redirect_url`, `redirect_time`, `added`, `staff`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" + sql_params = (edit_id, where, filter_type, filter_action, filter_from, filter_tripcode, filter_reason, redirect_url, redirect_time, timestamp(), staff_account['username']) # DO QUERY! if edit_id > 0: - UpdateDb( - "DELETE FROM `filters` WHERE `id` = %s" % str(edit_id)) - UpdateDb(sql_query) + UpdateDb("DELETE FROM `filters` WHERE `id` = %s", (edit_id,)) + UpdateDb(sql_query, sql_params) message = 'Filter edited.' else: - filt = FetchOne("SELECT `id` FROM `filters` WHERE `boards` = '%s' AND `type` = '%s' AND `from` = '%s'" % ( - where, str(filter_type), filter_from)) + filt = FetchOne("SELECT `id` FROM `filters` WHERE `boards` = %s AND `type` = %s AND `from` = %s", (where, filter_type, filter_from)) if not filt: - UpdateDb(sql_query) + UpdateDb(sql_query, sql_params) message = 'Filter added.' else: message = 'This filter already exists here:' + ' limit: message_shortened = message_shortened[:limit] - #message_shortened = formatting.close_html(message_shortened) + message_shortened = formatting.close_html(message_shortened) return True, message_shortened else: @@ -722,12 +723,14 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False): if not post["parentid"]: deleteReplies(post) - logging.info("Deleting post " + str(postid)) + logging.info("Deleting post %d - parentid: %d" % (post["id"], post["parentid"])) if deltype != 0 and post["parentid"]: # Soft delete (recycle bin) + logging.info("Soft delete") UpdateDb("UPDATE `posts` SET `IS_DELETED` = %s WHERE `boardid` = %s AND `id` = %s LIMIT 1", (deltype, board["id"], post["id"])) else: # Hard delete + logging.info("Hard delete") if post["file"]: deleteFile(post) @@ -745,10 +748,16 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False): (newlast["timestamp"], threadNumReplies(post["parentid"]), post["parentid"], board["id"])) if not post['parentid']: + logging.info("Unlinking html") if board['board_type'] == 1: - os.unlink(Settings.ROOT_DIR + str(board["dir"]) + "/res/" + str(post["timestamp"]) + ".html") + fname = Settings.ROOT_DIR + str(board["dir"]) + "/res/" + str(post["timestamp"]) + ".html" else: - os.unlink(Settings.ROOT_DIR + str(board["dir"]) + "/res/" + str(post["id"]) + ".html") + fname = Settings.ROOT_DIR + str(board["dir"]) + "/res/" + str(post["id"]) + ".html" + + try: + os.unlink(fname) + except FileNotFoundError: + logging.warn("Thread HTML (%s) didn't exist! Continuing..." % fname) regenerateHome() @@ -907,7 +916,7 @@ def autoclose_thread(parentid, t, replies): notice_post["bumped"] = get_parent_post(parentid, board["id"])["bumped"] notice_post["timestamp_formatted"] = str(replylimit) + " mensajes" notice_post.insert() - UpdateDb("UPDATE `posts` SET `locked` = 1 WHERE `boardid` = '%s' AND `id` = '%s' LIMIT 1" % (board["id"], _mysql.escape_string(parentid))) + UpdateDb("UPDATE `posts` SET `locked` = 1 WHERE `boardid` = %s AND `id` = %s LIMIT 1", (board["id"], parentid)) def pageNavigator(page_num, page_count, is_omitted=False): """ @@ -972,10 +981,12 @@ def flood_check(t,post,boardid): if not post["parentid"]: maxtime = round(t - int(board['threadsecs'])) - #lastpost = FetchOne("SELECT COUNT(*) FROM `posts` WHERE `ip` = INET6_ATON('%s') and `parentid` = 0 and `boardid` = '%s' and IS_DELETED = 0 AND timestamp > %d" % (str(post["ip"]), boardid, int(maxtime)), 0) + lastpost = FetchOne("SELECT `timestamp` FROM `posts` WHERE `ip` = INET6_ATON(%s) and `parentid` = 0 and `boardid` = %s and IS_DELETED = 0 AND timestamp > %s", + (post["ip"], boardid, maxtime)) # NO MATTER THE IP - lastpost = FetchOne("SELECT `timestamp` FROM `posts` WHERE `parentid` = 0 and `boardid` = %s and IS_DELETED = 0 AND timestamp > %s", + if not lastpost: + lastpost = FetchOne("SELECT `timestamp` FROM `posts` WHERE `parentid` = 0 and `boardid` = %s and IS_DELETED = 0 AND timestamp > %s", (boardid, maxtime)) else: maxtime = round(t - int(board['postsecs'])) @@ -990,11 +1001,10 @@ def flood_check(t,post,boardid): wait = int(int(board['threadsecs']) - (t - int(lastpost["timestamp"]))) raise UserError("Espera " + str(wait) + " segundos antes de crear otro hilo.") -def cut_home_msg(message, boardlength=0): +def cut_msg(message, limit): short_message = message.replace("
", " ") short_message = short_message.split("
")[0] short_message = re.compile(r"<[^>]*?>", re.DOTALL | re.IGNORECASE).sub("", short_message) # Removes HTML tags - limit = Settings.HOME_LASTPOSTS_LENGTH - boardlength if len(short_message) > limit: if isinstance(short_message, str): @@ -1002,6 +1012,9 @@ def cut_home_msg(message, boardlength=0): short_message = re.compile(r"&(.(?!;))*$", re.DOTALL | re.IGNORECASE).sub("", short_message) # Removes incomplete HTML return short_message +def cut_home_msg(message, boardlength=0): + return cut_msg(message, Settings.HOME_LASTPOSTS_LENGTH - boardlength) + def getLastAge(board_type, limit): threads = [] sql = "SELECT posts.id, boards.name AS board_fulln, boards.subname AS board_name, board_type, boards.dir, timestamp, bumped, last, length, thumb, CASE WHEN posts.subject = boards.subject THEN posts.message ELSE posts.subject END AS content FROM posts INNER JOIN boards ON boardid = boards.id WHERE parentid = 0 AND IS_DELETED = 0 AND boards.secret = 0 AND posts.locked < 3 AND boards.board_type = %s ORDER BY bumped DESC LIMIT %s" @@ -1209,12 +1222,13 @@ def latestAdd(post, postnum, postid, parent_post): else: url = '/%s/res/%s.html#%s' % (board['dir'], parentid, postid) - sql = "INSERT INTO last (id, boardid, board_name, timestamp, timestamp_formatted, content, url) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s')" % (str(postid), board['id'], _mysql.escape_string(board['name']), post['timestamp'], _mysql.escape_string(timestamp_formatted), _mysql.escape_string(content), _mysql.escape_string(url)) - UpdateDb(sql) + sql = "INSERT INTO last (id, boardid, board_name, timestamp, timestamp_formatted, content, url) VALUES (%s, %s, %s, %s, %s, %s, %s)" + params = (postid, board['id'], board['name'], post['timestamp'], timestamp_formatted, content, url) + UpdateDb(sql, params) def latestRemove(postid): board = Settings._.BOARD - UpdateDb("DELETE FROM last WHERE id = %s AND boardid = %s" % (str(postid), board['id'])) + UpdateDb("DELETE FROM last WHERE id = %s AND boardid = %s", (postid, board['id'])) def archiveThread(postid): import json @@ -1271,7 +1285,7 @@ def magic_ball(): return string -def discord_hook(post, url): +def discord_hook(post, parent_post, url): if not Settings.DISCORD_HOOK_URL: return @@ -1280,23 +1294,31 @@ def discord_hook(post, url): board = Settings._.BOARD - #data = {"embeds": [{ - # "title": post['subject'], - # "description": cut_home_msg(post['message'], 30), - # "url": "https://bienvenidoainternet.org" + url, # TODO: Parametrizar. - # "color": 11910504, - # "timestamp": datetime.datetime.utcfromtimestamp(post['timestamp']).isoformat(), - # "footer": { "text": board['name'] }, - # "thumbnail": { "url": "%s%s/thumb/%s" % (Settings.HOME_URL, board['dir'], post['thumb']) }, - # "author": { - # "name": "Nuevo hilo", - # "icon_url": "%s0/junk/w/shobon.gif" % Settings.HOME_URL - # }}] - #} - data = {"content": "test"} - jsondata = json.dumps(data, separators=(',',':')) - - opener = urllib.request.build_opener() - #opener.addheaders = [('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0')] - response = opener.open(Settings.DISCORD_HOOK_URL, jsondata, 6) - the_page = response.read() + if parent_post: + ptitle = "Nueva respuesta en {} ({})".format(html.unescape(parent_post["subject"]), parent_post["length"]+1) + else: + ptitle = "Nuevo hilo: {}".format(html.unescape(post['subject'])) + + data = {"embeds": [{ + "type": "rich", + "title": ptitle, + "description": html.unescape(cut_msg(post['message'], 200)), + "color": 11910504, + "url": "https://bienvenidoainternet.org" + url, # TODO: Parametrizar. + "timestamp": datetime.datetime.utcfromtimestamp(post['timestamp']).isoformat(), + "footer": { "text": board['name'] }, + }] + } + if post['thumb']: + data["embeds"][0]["thumbnail"] = {"url": "%s%s/thumb/%s" % (Settings.HOME_URL, board['dir'], post['thumb'])} + jsondata = json.dumps(data, separators=(',',':')).encode('utf-8') + + try: + req = urllib.request.Request(Settings.DISCORD_HOOK_URL) + req.add_header('Content-Type', 'application/json') + req.add_header('Content-Length', len(jsondata)) + req.add_header('User-Agent', "weabot/0.1") + response = urllib.request.urlopen(req, jsondata) + except urllib.error.HTTPError as e: + raise Exception(e.read()) + diff --git a/cgi/templates/board.html b/cgi/templates/board.html index 70718b8..3732ba9 100644 --- a/cgi/templates/board.html +++ b/cgi/templates/board.html @@ -241,11 +241,11 @@
Este hilo es viejo y desaparecerá pronto.
- + - +
Un post omitido. Haz clic en Responder para ver.
- 1: ?> + 1: ?>
#{thread['omitted']} posts omitidos. Haz clic en Responder para ver.
diff --git a/cgi/templates/board.jp.html b/cgi/templates/board.jp.html index f463dee..06a9391 100644 --- a/cgi/templates/board.jp.html +++ b/cgi/templates/board.jp.html @@ -238,9 +238,9 @@
このスレは古いので、もうすぐ消えます。
- + - 0: ?> + レス${thread['omitted']}件省略。全て読むには返信ボタンを押してください。 @@ -266,4 +266,4 @@
#{pagenav}
- \ No newline at end of file + diff --git a/cgi/templates/home.html b/cgi/templates/home.html index a9ca238..47ee5c7 100644 --- a/cgi/templates/home.html +++ b/cgi/templates/home.html @@ -29,10 +29,12 @@
Juegos Música Humanidades + Psicotrópicos

Conversación

Club VIP + Consejos World Lobby
diff --git a/cgi/templates/mobile/board.html b/cgi/templates/mobile/board.html index 8466c8f..f32a12c 100644 --- a/cgi/templates/mobile/board.html +++ b/cgi/templates/mobile/board.html @@ -4,12 +4,12 @@
- +

No.#{post['id']} eliminado por usuario.

- +

No.#{post['id']} eliminado por staff.

- +

#{post["subject"]} (#{thread['length']})

@@ -21,11 +21,11 @@
#{post['message']}
- + Recargar - +
El hilo ha sido cerrado. Ya no se puede postear en él.
@@ -52,4 +52,4 @@ - \ No newline at end of file + diff --git a/cgi/templates/mobile/txt_thread.html b/cgi/templates/mobile/txt_thread.html index 3df16fc..8397fc7 100644 --- a/cgi/templates/mobile/txt_thread.html +++ b/cgi/templates/mobile/txt_thread.html @@ -71,4 +71,4 @@ - \ No newline at end of file + diff --git a/cgi/templates/paint.html b/cgi/templates/paint.html index 945a8d2..4787674 100644 --- a/cgi/templates/paint.html +++ b/cgi/templates/paint.html @@ -13,8 +13,8 @@ - - + + @@ -27,8 +27,8 @@ - - + + diff --git a/cgi/weabot.py b/cgi/weabot.py index e0e941a..ff3c9d3 100755 --- a/cgi/weabot.py +++ b/cgi/weabot.py @@ -126,6 +126,8 @@ class weabot(object): self._newcookies = None def run(self): + clearCache() + path_split = self.environ["PATH_INFO"].split("/") caught = False @@ -454,7 +456,7 @@ class weabot(object): # Disallow posting if the site OR board is in maintenance if Settings.MAINTENANCE and board["dir"] != 'polka': raise UserError(_("%s is currently under maintenance. We'll be back.") % Settings.SITE_TITLE) - if board["locked"] == '1': + if board["locked"] == 1: raise UserError(_("This board is closed. You can't post in it.")) # create post object @@ -471,17 +473,17 @@ class weabot(object): parent_timestamp = parent_post['timestamp'] post["parentid"] = parent_post['id'] post["bumped"] = parent_post['bumped'] - if parent_post['locked'] == '1': + if parent_post['locked'] == 1: raise UserError(_("The thread is closed. You can't post in it.")) # check if the user is flooding flood_check(t, post, board["id"]) # use fields only if enabled - if board["disable_name"] != '1': + if not board["disable_name"]: post["name"] = cleanString(name) post["email"] = cleanString(email, quote=True) - if board["disable_subject"] != '1': + if not board["disable_subject"]: post["subject"] = cleanString(subject) # process tripcodes @@ -495,7 +497,7 @@ class weabot(object): if not post["parentid"] and board["dir"] not in ['bai', 'world']: # creating thread - __extend = re.compile(r"^!extend(:\w+)(:\w+)?\n") + __extend = re.compile(r"!extend(:\w+)(:\w+)?\n", re.IGNORECASE) res = __extend.match(message) if res: extend = res.groups() @@ -510,7 +512,8 @@ class weabot(object): # add function messages if extend_str: - extend_str = extend_str.replace('!extend', 'EXTEND') + extend_str = extend_str[1:] + extend_str = extend_str.replace('extend', 'EXTEND') post["message"] += '
' + extend_str + ' configurado.' if not post["parentid"] and post["email"].lower() == 'sage': @@ -527,12 +530,6 @@ class weabot(object): capcode = Settings.CAPCODES[post["name"]] if post["tripcode"] == (Settings.TRIP_CHAR + capcode[0]): post["name"], post["tripcode"] = capcode[1], capcode[2] - # if board['board_type'] == '1': - # post["name"], post["tripcode"] = capcode[1], '' - # else: - # post["name"] = post["tripcode"] = '' - # post["message"] = ('[%s]
' % capcode[2]) + post["message"] - cap_id, hide_end, use_icon = capcode[3], capcode[4], capcode[5] # hide ip if necessary @@ -566,28 +563,28 @@ class weabot(object): try: # 1: ID if extend[0] == ':no': - board["useid"] = '0' + board["useid"] = 0 elif extend[0] == ':yes': - board["useid"] = '1' + board["useid"] = 1 elif extend[0] == ':force': - board["useid"] = '2' + board["useid"] = 2 elif extend[0] == ':extra': - board["useid"] = '3' + board["useid"] = 3 # 2: Slip if extend[1] == ':no': - board["slip"] = '0' + board["slip"] = 0 elif extend[1] == ':yes': - board["slip"] = '1' + board["slip"] = 1 elif extend[1] == ':domain': - board["slip"] = '2' + board["slip"] = 2 elif extend[1] == ':verbose': - board["slip"] = '3' + board["slip"] = 3 elif extend[1] == ':country': - board["countrycode"] = '1' + board["countrycode"] = 1 elif extend[1] == ':all': - board["slip"] = '3' - board["countrycode"] = '1' + board["slip"] = 3 + board["countrycode"] = 1 except IndexError: pass @@ -743,7 +740,7 @@ class weabot(object): host = '*.' + host elif ':' in ip: iprs = ip.split(':') - host = '%s:%s:%s:%s:*.*.*.*' % (iprs[0], iprs[1], iprs[2], iprs[3]) + host = '%s:%s:*:*:*.*.*.*' % (iprs[0], iprs[1]) else: iprs = ip.split('.') host = '%s.%s.*.*' % (iprs[0], iprs[1]) @@ -824,7 +821,7 @@ class weabot(object): thread_length = threadNumReplies(post["parentid"]) # bump if not saged - if 'sage' not in post["email"].lower() and parent_post['locked'] != '2': + if 'sage' not in post["email"].lower() and parent_post['locked'] != 2: UpdateDb("UPDATE `posts` SET bumped = %s WHERE (`id` = %s OR `parentid` = %s) AND `boardid` = %s", (post["timestamp"], post["parentid"], post["parentid"], board["id"])) @@ -855,10 +852,10 @@ class weabot(object): if Settings.ENABLE_RSS: latestAdd(post, thread_length, postid, parent_post) # call discord hook - if Settings.ENABLE_DISCORD_HOOK and not post["parentid"]: + if Settings.ENABLE_DISCORD_HOOK: hook_url = make_url( postid, post, parent_post or post, True, False) - discord_hook(post, hook_url) + discord_hook(post, parent_post, hook_url) return (post_url, ttaken, postid) -- cgit v1.2.1-18-gbd029