Make referrer verification exceptions non-fatal
This commit is contained in:
parent
b0a5a53b09
commit
bccfcff19d
|
@ -6,7 +6,8 @@ import time
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
import rophako.jsondb as JsonDB
|
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):
|
def track_visit(request, session):
|
||||||
"""Main logic to track and log visitor details."""
|
"""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.
|
# See if the URL really links back to us.
|
||||||
hostname = server_name()
|
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:
|
if hostname in r.text:
|
||||||
# Log it.
|
# Log it.
|
||||||
db = list()
|
db = list()
|
||||||
|
@ -101,6 +106,9 @@ def log_referrer(request, link):
|
||||||
db.append(link)
|
db.append(link)
|
||||||
JsonDB.commit("traffic/referrers", db, cache=False)
|
JsonDB.commit("traffic/referrers", db, cache=False)
|
||||||
return link
|
return link
|
||||||
|
except Exception as e:
|
||||||
|
handle_exception(e)
|
||||||
|
return None
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ def handle_exception(error):
|
||||||
|
|
||||||
username = "anonymous"
|
username = "anonymous"
|
||||||
try:
|
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"]
|
username = g.info["session"]["username"]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
@ -227,7 +227,12 @@ def handle_exception(error):
|
||||||
stacktrace = error + "\n\n" \
|
stacktrace = error + "\n\n" \
|
||||||
+ "==== Start Traceback ====\n" \
|
+ "==== Start Traceback ====\n" \
|
||||||
+ traceback.format_exc() \
|
+ 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
|
# Construct the subject and message
|
||||||
subject = "Internal Server Error on {} - {} - {}".format(
|
subject = "Internal Server Error on {} - {} - {}".format(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user