diff --git a/main.py b/main.py index 9ca003f..0d1cdbe 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import asyncio from markupsafe import escape from unificontrol import UnifiClient from dotenv import load_dotenv @@ -5,12 +6,14 @@ from os import getenv from ssl import get_server_certificate from flask import Flask, request, render_template, Response, send_from_directory import os +from pyVoIP.VoIP import VoIPPhone app = Flask(__name__) app.config['TEMPLATES_AUTO_RELOAD'] = True global unifi VISITOR_COUNT_FILE = "visitor_count" +SIP = None def main(): if not os.path.exists(VISITOR_COUNT_FILE): @@ -24,22 +27,30 @@ def main(): USERNAME = str(getenv("USERNAME")) PASSWORD = str(getenv("PASSWORD")) - #cert = get_server_certificate((HOSTNAME, 443)) + global SIP + SIP=VoIPPhone( + str(getenv("SIP_SERVER")), int(getenv("SIP_PORT")), str(getenv("SIP_USERNAME")), str(getenv("SIP_PASSWORD"))) + SIP.start() + import time + for _ in range(1000): + print(SIP.get_status()) + time.sleep(1) - #global unifi - #unifi = UnifiClient(host=HOSTNAME, - # username=USERNAME, password=PASSWORD, cert=cert) - app.run(host="0.0.0.0", port=8080) + cert = get_server_certificate((HOSTNAME, 443)) -@app.route('/guest/s/default/', methods=["GET"]) -def root(): + global unifi + unifi = UnifiClient(host=HOSTNAME, + username=USERNAME, password=PASSWORD, cert=cert) + + app.run(host="0.0.0.0", port=80) + +def visitor_count(): 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)) @@ -47,20 +58,25 @@ def root(): visitor_count = visitors except Exception as e: print(f"error {e}") + return visitor_count - ap = escape(request.args.get('ap')) + +@app.route('/guest/s/default/', methods=["GET"]) +def root(): 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, visitor_count=visitor_count) + page = render_template("index.html", dialing_up=False, id=id, visitor_count=visitor_count()) response = Response(page, mimetype="text/html") return response @app.route("/dialup", methods=["POST"]) -def accept(): - unifi.authorize_guest(id, 1) - return "no" +def dialup(): + # Spawn audio on phone + # authorize guest after a certain amount of time + id = escape(request.args.get('id')) + page = render_template("index.html", dialing_up=True, id=id, visitor_count=visitor_count()) + #unifi.authorize_guest(id, 1) + response = Response(page, mimetype="text/html") + return response @app.route('/afbeeldingen/') def static_folder(path): diff --git a/requirements.txt b/requirements.txt index ffb9ad1..15cd55b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,3 +13,4 @@ requests==2.32.3 unificontrol @ git+https://github.com/ThijsRay/unificontrol@bc595d0b17d38f45d624fe08c144e322484fe298 urllib3==2.4.0 Werkzeug==3.1.3 +pyVoIP==1.6.8 diff --git a/templates/index.html b/templates/index.html index 414691a..eda2f75 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,6 +13,38 @@ visibility = (visibility === 'visible') ? 'hidden' : 'visible'; }, 250); })(); + + {% if dialing_up %} + window.onload = function () { + var status = document.getElementById('status'); + console.log(status); + status.innerHTML = "Openen van telefoonlijn..."; + + setTimeout(function() { + status.innerHTML = "Bellen naar TechInc..."; + }, 768); + + setTimeout(function() { + status.innerHTML = "Ontvang verbindingsopties..."; + }, 5086); + + setTimeout(function() { + status.innerHTML = "Uitzetten van echo onderdrukking..."; + }, 8861); + + setTimeout(function() { + status.innerHTML = "Breedbandspectrum peilen..."; + }, 12123); + + setTimeout(function() { + status.innerHTML = "Equalizer en echo-onderdrukkingstraining..."; + }, 13695); + + setTimeout(function() { + status.innerHTML = "Verbinding met TechInc is gelegd!"; + }, 18326); + } + {% endif %} @@ -78,10 +110,16 @@

U BENT BEZOEKER {{visitor_count}}!

-
+ {% if dialing_up %} +
+ +
+ {% else %} +
+ {% endif %}