Moved login and register to user POST | Added referrer analytics
This commit is contained in:
parent
63ce632ce9
commit
6e9a24ae59
2 changed files with 41 additions and 12 deletions
|
@ -16,6 +16,7 @@ from modules.Common import *
|
|||
|
||||
KnownCookies = []
|
||||
RecentArticles = {}
|
||||
RefferedArticles = {}
|
||||
|
||||
def guess_type(path):
|
||||
|
||||
|
@ -480,12 +481,15 @@ def ArticlePage(server, url):
|
|||
|
||||
user = validate(server.cookie)
|
||||
|
||||
referrer = server.headers.get("referer", "")
|
||||
|
||||
if url.endswith(".md"):
|
||||
url = url.replace(".md", "")
|
||||
|
||||
# Recording when was the last time
|
||||
# the article loaded.
|
||||
RecentArticles["/"+url] = time.time()
|
||||
RefferedArticles["/"+url] = referrer
|
||||
|
||||
config = Set.Load()
|
||||
tab, article, *rest = url.split("/")
|
||||
|
@ -542,7 +546,14 @@ def ArticlePage(server, url):
|
|||
html = html + '<br><center><details><summary class="button">👁 '+views+'</summary>'
|
||||
html = html + """
|
||||
<iframe width="100%" height="500px" style="border:none; border-radius:25px;" src="/graph"""+server.path+""""></iframe>
|
||||
<br><br>
|
||||
<br><br>"""
|
||||
|
||||
referrers = Articles.get(article, {}).get("views", {}).get("referrers", {})
|
||||
if referrers:
|
||||
for referrer in referrers:
|
||||
html = html + referrer + " : 👁 "+str(referrers[referrer]) + "<br>\n"
|
||||
|
||||
html = html + """
|
||||
</details>
|
||||
"""
|
||||
|
||||
|
@ -895,7 +906,7 @@ def LoginPage(server):
|
|||
|
||||
<div class="dark_box">
|
||||
|
||||
<form action="do_login">
|
||||
<form action="do_login" method="post">
|
||||
|
||||
<img style="vertical-align: middle" src="/icon/user">
|
||||
<input class="button" style="width:90%" maxlength="500" id="user_name" required="" name="user_name" pattern="[A-Za-z0-9\.\-\_\]*" placeholder="Username..."></input>
|
||||
|
@ -952,7 +963,7 @@ def RegisterPage(server):
|
|||
|
||||
<div class="dark_box">
|
||||
|
||||
<form action="do_register">
|
||||
<form action="do_register" method="post">
|
||||
"""
|
||||
|
||||
if wrongcode:
|
||||
|
@ -1369,6 +1380,9 @@ def User(username, stretch=False):
|
|||
def Graph(server, url):
|
||||
|
||||
|
||||
if url.endswith(".md"):
|
||||
url = url.replace(".md", "")
|
||||
|
||||
# If there are any values after ? in the path
|
||||
# which means, that somebody is sending the old
|
||||
# version of the graph link from the legacy code
|
||||
|
@ -1392,7 +1406,7 @@ def Graph(server, url):
|
|||
# Sometimes scrapers try to load graph without
|
||||
# loading the article first. We don't want to count
|
||||
# it as a view.
|
||||
if time.time()-10 > RecentArticles.get(url, 0):
|
||||
if time.time()-20 > RecentArticles.get(url, 0):
|
||||
print(consoleForm(server.cookie), "Article wasn't loaded, scrapers!")
|
||||
AccessDenied(server)
|
||||
return
|
||||
|
@ -1400,6 +1414,10 @@ def Graph(server, url):
|
|||
|
||||
user = validate(server.cookie)
|
||||
|
||||
# Store general analytics about which search engines were used.
|
||||
# To get to this article.
|
||||
referrer = RefferedArticles.get(url, "")
|
||||
|
||||
html = """
|
||||
<head>
|
||||
<link media="all" href="/css" type="text/css" rel="stylesheet" /> <!-- CSS theme link -->
|
||||
|
@ -1414,8 +1432,7 @@ def Graph(server, url):
|
|||
|
||||
"""
|
||||
|
||||
if url.endswith(".md"):
|
||||
url = url.replace(".md", "")
|
||||
|
||||
|
||||
try:
|
||||
with open(Set.Folder()+"/tabs"+url+"/metadata.json") as o:
|
||||
|
@ -1464,6 +1481,14 @@ def Graph(server, url):
|
|||
article["views"]["amount"] += 1
|
||||
article["views"]["viewers"].append(cookie)
|
||||
|
||||
if "referrers" not in article["views"]:
|
||||
article["views"]["referrers"] = {}
|
||||
if referrer and referrer not in article["views"]["referrers"]:
|
||||
article["views"]["referrers"][referrer] = 0
|
||||
|
||||
if referrer:
|
||||
article["views"]["referrers"][referrer] += 1
|
||||
|
||||
dates = article["views"]["dates"]
|
||||
date = datetime.now().strftime(dateformat)
|
||||
dates[date] = dates.get(date, 0) + 1
|
||||
|
|
|
@ -69,7 +69,7 @@ class handler(BaseHTTPRequestHandler):
|
|||
# Failing early to make sure that nobody will
|
||||
# try attacking this part of the server.
|
||||
|
||||
commands = ["do_edit"]
|
||||
commands = ["do_edit", "do_login", "do_register"]
|
||||
found = False
|
||||
for i in commands:
|
||||
if i in self.path:
|
||||
|
@ -103,6 +103,12 @@ class handler(BaseHTTPRequestHandler):
|
|||
if self.path[1:].startswith("do_edit"):
|
||||
Render.Publish(self)
|
||||
|
||||
elif self.path[1:].startswith("do_login"):
|
||||
Render.Login(self)
|
||||
|
||||
elif self.path[1:].startswith("do_register"):
|
||||
Render.Register(self)
|
||||
|
||||
else:
|
||||
Render.NotFound(self)
|
||||
|
||||
|
@ -185,11 +191,9 @@ class handler(BaseHTTPRequestHandler):
|
|||
elif self.path[1:].startswith("log_out"):
|
||||
Render.LogOut(self)
|
||||
|
||||
elif self.path[1:].startswith("do_login"):
|
||||
Render.Login(self)
|
||||
|
||||
elif self.path[1:].startswith("do_register"):
|
||||
Render.Register(self)
|
||||
|
||||
|
||||
|
||||
elif self.path[1:].startswith("read_notification"):
|
||||
Render.ReadNotification(self)
|
||||
|
|
Loading…
Add table
Reference in a new issue