-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrackerWebHandler.py
More file actions
39 lines (34 loc) · 1.43 KB
/
trackerWebHandler.py
File metadata and controls
39 lines (34 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging
from flask import send_file, request, redirect
import siteHandler
import trackerHandler
@siteHandler.app.route("/t/<uuid:trackerId>", methods=['GET'])
@siteHandler.app.route("/t/<uuid:trackerId>/", methods=['GET'])
@siteHandler.app.route("/t/<uuid:trackerId>/<path:path>", methods=['GET'])
def trackerGet(trackerId, path=None):
"""
Called by Flask when a client requests a Tracker link or similar
:param trackerId: the UUID of the tracker
:param path: an ignored variable that lets Flask ignore everything after the UUID in the URL
:return: Sends a 1x1 pixel PNG to the client
"""
tracker = trackerHandler.getTrackerById(trackerId)
if tracker is not None:
logging.info(f"Hit on tracker with UUID: {trackerId} from IP: {request.remote_addr}")
tracker.registerHit(request.remote_addr)
else:
logging.debug(f"Hit on NONEXISTENT tracker with UUID: {trackerId}")
return send_file('static/pixel.png', mimetype='image/png')
@siteHandler.app.route("/generate", methods=["POST"])
def genLink():
"""
Called by Flask when a client generates a new link
:return: the id for the tracker link
"""
if not siteHandler.checkAuthed(request):
return redirect('/login')
if 'desc' not in request.form:
return redirect("/view")
# return ignored v
trackerHandler.generateTracker(request.cookies['username'], request.form['desc'])
return redirect("/view")