fix 500 error

master
Aevann 2023-07-14 06:00:12 +03:00
parent 1d726ebd77
commit 63fa768883
2 changed files with 5 additions and 5 deletions

View File

@ -11,6 +11,10 @@ from files.__main__ import app, limiter, get_CF, redis_instance
def before_request(): def before_request():
g.v = None g.v = None
g.agent = request.headers.get("User-Agent")
if not g.agent and request.path != '/kofi':
abort(403, 'Please use a "User-Agent" header!')
if request.host != SITE: if request.host != SITE:
abort(403, "Unauthorized host provided!") abort(403, "Unauthorized host provided!")
@ -20,10 +24,6 @@ def before_request():
if request.headers.get("CF-Worker"): if request.headers.get("CF-Worker"):
abort(403, "Cloudflare workers are not allowed to access this website!") abort(403, "Cloudflare workers are not allowed to access this website!")
g.agent = request.headers.get("User-Agent", "")
if not g.agent and request.path != '/kofi':
abort(403, 'Please use a "User-Agent" header!')
if not get_setting('bots') and request.headers.get("Authorization"): if not get_setting('bots') and request.headers.get("Authorization"):
abort(403) abort(403)

View File

@ -45,7 +45,7 @@ def calc_users():
if v: if v:
if session["session_id"] in loggedout: del loggedout[session["session_id"]] if session["session_id"] in loggedout: del loggedout[session["session_id"]]
loggedin[v.id] = timestamp loggedin[v.id] = timestamp
else: elif hasattr(g, 'agent') and g.agent:
ua = str(user_agents.parse(g.agent)) ua = str(user_agents.parse(g.agent))
if 'spider' not in ua.lower() and 'bot' not in ua.lower(): if 'spider' not in ua.lower() and 'bot' not in ua.lower():
loggedout[session["session_id"]] = (timestamp, ua) loggedout[session["session_id"]] = (timestamp, ua)