aboutsummaryrefslogtreecommitdiff
path: root/cgi/weabot.py
diff options
context:
space:
mode:
Diffstat (limited to 'cgi/weabot.py')
-rwxr-xr-xcgi/weabot.py46
1 files changed, 27 insertions, 19 deletions
diff --git a/cgi/weabot.py b/cgi/weabot.py
index 636eb02..5d565d5 100755
--- a/cgi/weabot.py
+++ b/cgi/weabot.py
@@ -23,7 +23,7 @@ from formatting import *
from post import *
from img import *
-__version__ = "0.10.5"
+__version__ = "0.10.8"
# Set to True to disable weabot's exception routing and enable profiling
_DEBUG = False
@@ -202,7 +202,7 @@ class weabot(object):
OpenDb()
board = setBoard(path_split[2])
caught = True
- if board['board_type'] != '1':
+ if board['board_type'] != 1:
raise UserError("No disponible para esta sección.")
self.output = threadList(0)
elif path_split[1] == "mobile":
@@ -311,21 +311,18 @@ class weabot(object):
caught = True
OpenDb()
board = FetchOne("SELECT `id`, `dir`, `board_type` FROM `boards` WHERE `secret` = 0 AND `id` <> 1 AND `id` <> 13 AND `id` <> 34 ORDER BY RAND() LIMIT 1")
- thread = FetchOne("SELECT `id`, `timestamp` FROM `posts` WHERE `parentid` = 0 AND `boardid` = %s ORDER BY RAND() LIMIT 1" % board['id'])
- if board['board_type'] == '1':
- url = Settings.HOME_URL + \
- board['dir'] + '/read/' + thread['timestamp'] + '/'
+ thread = FetchOne("SELECT `id`, `timestamp` FROM `posts` WHERE `parentid` = 0 AND `boardid` = %s ORDER BY RAND() LIMIT 1", (board['id'],))
+ if board['board_type'] == 1:
+ url = f"{Settings.HOME_URL}{board['dir']}/read/{thread['timestamp']}/"
else:
- url = Settings.HOME_URL + \
- board['dir'] + '/res/' + thread['id'] + '.html'
+ url = f"{Settings.HOME_URL}{board['dir']}/res/{thread['id']}.html"
self.output += '<html xmlns="http://www.w3.org/1999/xhtml"><meta http-equiv="refresh" content="0;url=%s" /><body><p>...</p></body></html>' % url
elif path_split[1] == "nostalgia":
caught = True
OpenDb()
thread = FetchOne(
"SELECT `timestamp` FROM `archive` WHERE `boardid` = 9 AND `timestamp` < 1462937230 ORDER BY RAND() LIMIT 1")
- url = Settings.HOME_URL + '/zonavip/read/' + \
- thread['timestamp'] + '/'
+ url = f"{Settings.HOME_URL}/zonavip/read/{thread['timestamp']}/"
self.output += '<html xmlns="http://www.w3.org/1999/xhtml"><meta http-equiv="refresh" content="0;url=%s" /><body><p>...</p></body></html>' % url
elif path_split[1] == "banned":
OpenDb()
@@ -404,9 +401,20 @@ class weabot(object):
_STARTTIME = time.process_time() # Comment if not debug
if Settings.PROXY_BANS and ip not in Settings.PROXY_WHITELIST and (boarddir not in Settings.EXCLUDE_GLOBAL_BANS):
- if addressIsTor(ip) or addressIsProxy(ip) or addressIsBannedCountry(ip) or not addressIsES(ip):
+ if addressIsTor(ip):
+ logging.warn("Proxy: Tor %s" % ip)
+ raise UserError("Proxy prohibido.")
+ if addressIsProxy(ip):
+ logging.warn("Proxy: Proxy %s" % ip)
+ raise UserError("Proxy prohibido.")
+ if addressIsBannedCountry(ip):
+ logging.warn("Proxy: Banned country %s" % ip)
+ raise UserError("Proxy prohibido.")
+ if not addressIsES(ip):
+ logging.warn("Proxy: Not ES %s" % ip)
raise UserError("Proxy prohibido.")
if hostIsBanned(ip):
+ logging.warn("Proxy: Blacklisted host %s" % ip)
raise UserError("Sufijo de host en lista negra.")
# open database
@@ -595,7 +603,7 @@ class weabot(object):
self.environ["HTTP_USER_AGENT"], cap_id, hide_end, (board["countrycode"] in [1, 2]))
# use for future file checks
- xfile = (file is not None or oek_file)
+ xfile = (file or oek_file)
# textboard inforcements (change it to settings maybe?)
if board['board_type'] == 1:
@@ -640,7 +648,7 @@ class weabot(object):
if file and not noimage:
post = processImage(post, file, t, file_original,
- (spoil and board['allow_spoilers'] == '1'))
+ (spoil and board['allow_spoilers']))
if oek_file:
# Remove temporary oekaki file if everything went right
@@ -652,11 +660,11 @@ class weabot(object):
pass # Just keep it if anything went wrong
# slip
- if board["slip"] != '0':
+ if board["slip"]:
slips = []
# name
- if board["slip"] in ['1', '3']:
+ if board["slip"] in [1, 3]:
if time.strftime("%H") in ['00', '24'] and time.strftime("%M") == '00' and time.strftime("%S") == '00':
host_nick = '000000'
else:
@@ -762,15 +770,15 @@ class weabot(object):
post["name"] += " <em>[%s]</em>" % country
# set expiration date if necessary
- if board["maxage"] != 0 and not post["parentid"]:
+ if board["maxage"] > 0 and not post["parentid"]:
if board["dir"] == '2d':
date_format = '%m月%d日'
date_format_y = '%Y年%m月'
else:
date_format = '%d/%m'
date_format_y = '%m/%Y'
- post["expires"] = int(t) + (int(board["maxage"]) * 86400)
- if int(board["maxage"]) >= 365:
+ post["expires"] = int(t) + (board["maxage"] * 86400)
+ if board["maxage"] >= 365:
date_format = date_format_y
post["expires_formatted"] = datetime.datetime.fromtimestamp(
post["expires"]).strftime(date_format)
@@ -959,7 +967,7 @@ class weabot(object):
raise UserError(_("Post doesn't exist."))
# generate link
- if board["board_type"] == '1':
+ if board["board_type"] == 1:
parent_post = get_parent_post(post["parentid"], board["id"])
link = "/%s/read/%s/%s" % (board["dir"],
parent_post["timestamp"], postshow)