diff --git a/.gitignore b/.gitignore index 4c49bd7..a20d6f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .env +visitor_count diff --git a/main.py b/main.py index ed8c7f6..9ca003f 100644 --- a/main.py +++ b/main.py @@ -4,12 +4,20 @@ from dotenv import load_dotenv from os import getenv from ssl import get_server_certificate from flask import Flask, request, render_template, Response, send_from_directory +import os app = Flask(__name__) app.config['TEMPLATES_AUTO_RELOAD'] = True global unifi +VISITOR_COUNT_FILE = "visitor_count" + def main(): + if not os.path.exists(VISITOR_COUNT_FILE): + os.mknod(VISITOR_COUNT_FILE) + with open(VISITOR_COUNT_FILE, "w") as f: + f.write("0") + load_dotenv() HOSTNAME = str(getenv("HOSTNAME")) @@ -22,16 +30,30 @@ def main(): #unifi = UnifiClient(host=HOSTNAME, # username=USERNAME, password=PASSWORD, cert=cert) - app.run(host="0.0.0.0", port=80) + app.run(host="0.0.0.0", port=8080) @app.route('/guest/s/default/', methods=["GET"]) def root(): + visitor_count = 1337 + # Yes there is a race condition here, I don't care + try: + with open(VISITOR_COUNT_FILE, "r+") as f: + visitors = int(f.read().strip()) + print("visitors:", visitors) + visitors += 1 + f.seek(0) + f.write(str(visitors)) + f.truncate() + visitor_count = visitors + except Exception as e: + print(f"error {e}") + ap = escape(request.args.get('ap')) id = escape(request.args.get('id')) ssid = escape(request.args.get('ssid')) url = escape(request.args.get('url')) - page = render_template("index.html", ap=ap, id=id, ssid=ssid, url=url) + page = render_template("index.html", ap=ap, id=id, ssid=ssid, url=url, visitor_count=visitor_count) response = Response(page, mimetype="text/html") return response diff --git a/templates/index.html b/templates/index.html index 44f27be..414691a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -75,13 +75,14 @@
+