Make referrer verification exceptions non-fatal
This commit is contained in:
parent
b0a5a53b09
commit
bccfcff19d
|
@ -6,7 +6,8 @@ import time
|
|||
import requests
|
||||
|
||||
import rophako.jsondb as JsonDB
|
||||
from rophako.utils import remote_addr, pretty_time, server_name
|
||||
from rophako.utils import (remote_addr, pretty_time, server_name,
|
||||
handle_exception)
|
||||
|
||||
def track_visit(request, session):
|
||||
"""Main logic to track and log visitor details."""
|
||||
|
@ -91,7 +92,11 @@ def log_referrer(request, link):
|
|||
|
||||
# See if the URL really links back to us.
|
||||
hostname = server_name()
|
||||
r = requests.get(link)
|
||||
try:
|
||||
r = requests.get(link,
|
||||
timeout=5,
|
||||
verify=False, # Don't do SSL verification
|
||||
)
|
||||
if hostname in r.text:
|
||||
# Log it.
|
||||
db = list()
|
||||
|
@ -101,6 +106,9 @@ def log_referrer(request, link):
|
|||
db.append(link)
|
||||
JsonDB.commit("traffic/referrers", db, cache=False)
|
||||
return link
|
||||
except Exception as e:
|
||||
handle_exception(e)
|
||||
return None
|
||||
|
||||
return None
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ def handle_exception(error):
|
|||
|
||||
username = "anonymous"
|
||||
try:
|
||||
if "username" in g.info["session"]:
|
||||
if hasattr(g, "info") and "session" in g.info and "username" in g.info["session"]:
|
||||
username = g.info["session"]["username"]
|
||||
except:
|
||||
pass
|
||||
|
@ -227,7 +227,12 @@ def handle_exception(error):
|
|||
stacktrace = error + "\n\n" \
|
||||
+ "==== Start Traceback ====\n" \
|
||||
+ traceback.format_exc() \
|
||||
+ "==== End Traceback ====\n"
|
||||
+ "==== End Traceback ====\n\n" \
|
||||
+ "Request Information\n" \
|
||||
+ "-------------------\n" \
|
||||
+ "Address: " + remote_addr() + "\n" \
|
||||
+ "User Agent: " + request.user_agent.string + "\n" \
|
||||
+ "Referrer: " + request.referrer
|
||||
|
||||
# Construct the subject and message
|
||||
subject = "Internal Server Error on {} - {} - {}".format(
|
||||
|
|
Loading…
Reference in New Issue
Block a user