add visitor count and status indicators
This commit is contained in:
parent
b439a4a06f
commit
ffcc9b3675
3 changed files with 72 additions and 17 deletions
48
main.py
48
main.py
|
|
@ -1,3 +1,4 @@
|
||||||
|
import asyncio
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
from unificontrol import UnifiClient
|
from unificontrol import UnifiClient
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
@ -5,12 +6,14 @@ from os import getenv
|
||||||
from ssl import get_server_certificate
|
from ssl import get_server_certificate
|
||||||
from flask import Flask, request, render_template, Response, send_from_directory
|
from flask import Flask, request, render_template, Response, send_from_directory
|
||||||
import os
|
import os
|
||||||
|
from pyVoIP.VoIP import VoIPPhone
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
||||||
global unifi
|
global unifi
|
||||||
|
|
||||||
VISITOR_COUNT_FILE = "visitor_count"
|
VISITOR_COUNT_FILE = "visitor_count"
|
||||||
|
SIP = None
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if not os.path.exists(VISITOR_COUNT_FILE):
|
if not os.path.exists(VISITOR_COUNT_FILE):
|
||||||
|
|
@ -24,22 +27,30 @@ def main():
|
||||||
USERNAME = str(getenv("USERNAME"))
|
USERNAME = str(getenv("USERNAME"))
|
||||||
PASSWORD = str(getenv("PASSWORD"))
|
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"])
|
global unifi
|
||||||
def root():
|
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
|
visitor_count = 1337
|
||||||
# Yes there is a race condition here, I don't care
|
# Yes there is a race condition here, I don't care
|
||||||
try:
|
try:
|
||||||
with open(VISITOR_COUNT_FILE, "r+") as f:
|
with open(VISITOR_COUNT_FILE, "r+") as f:
|
||||||
visitors = int(f.read().strip())
|
visitors = int(f.read().strip())
|
||||||
print("visitors:", visitors)
|
|
||||||
visitors += 1
|
visitors += 1
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
f.write(str(visitors))
|
f.write(str(visitors))
|
||||||
|
|
@ -47,20 +58,25 @@ def root():
|
||||||
visitor_count = visitors
|
visitor_count = visitors
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"error {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'))
|
id = escape(request.args.get('id'))
|
||||||
ssid = escape(request.args.get('ssid'))
|
page = render_template("index.html", dialing_up=False, id=id, visitor_count=visitor_count())
|
||||||
url = escape(request.args.get('url'))
|
|
||||||
|
|
||||||
page = render_template("index.html", ap=ap, id=id, ssid=ssid, url=url, visitor_count=visitor_count)
|
|
||||||
response = Response(page, mimetype="text/html")
|
response = Response(page, mimetype="text/html")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@app.route("/dialup", methods=["POST"])
|
@app.route("/dialup", methods=["POST"])
|
||||||
def accept():
|
def dialup():
|
||||||
unifi.authorize_guest(id, 1)
|
# Spawn audio on phone
|
||||||
return "no"
|
# 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/<path:path>')
|
@app.route('/afbeeldingen/<path:path>')
|
||||||
def static_folder(path):
|
def static_folder(path):
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,4 @@ requests==2.32.3
|
||||||
unificontrol @ git+https://github.com/ThijsRay/unificontrol@bc595d0b17d38f45d624fe08c144e322484fe298
|
unificontrol @ git+https://github.com/ThijsRay/unificontrol@bc595d0b17d38f45d624fe08c144e322484fe298
|
||||||
urllib3==2.4.0
|
urllib3==2.4.0
|
||||||
Werkzeug==3.1.3
|
Werkzeug==3.1.3
|
||||||
|
pyVoIP==1.6.8
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,38 @@
|
||||||
visibility = (visibility === 'visible') ? 'hidden' : 'visible';
|
visibility = (visibility === 'visible') ? 'hidden' : 'visible';
|
||||||
}, 250);
|
}, 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 %}
|
||||||
</SCRIPt>
|
</SCRIPt>
|
||||||
</HEAD>
|
</HEAD>
|
||||||
<BODY BACKGROUND="/afbeeldingen/achtergrond.jpg" TEXT="black">
|
<BODY BACKGROUND="/afbeeldingen/achtergrond.jpg" TEXT="black">
|
||||||
|
|
@ -78,10 +110,16 @@
|
||||||
<CENTER>
|
<CENTER>
|
||||||
<H2>U BENT BEZOEKER <FONT COLOR="red"><BLINK>{{visitor_count}}</BLINK></FONT>!</H2>
|
<H2>U BENT BEZOEKER <FONT COLOR="red"><BLINK>{{visitor_count}}</BLINK></FONT>!</H2>
|
||||||
</CENTER>
|
</CENTER>
|
||||||
<FORM METHOD="POST" ACTION="/connect">
|
{% if dialing_up %}
|
||||||
|
<CENTER>
|
||||||
|
<I><FONT SIZE="+3" ID="status"></FONT></I>
|
||||||
|
</CENTER>
|
||||||
|
{% else %}
|
||||||
|
<FORM METHOD="POST" ACTION="/dialup">
|
||||||
<INPUT TYPE="hidden" NAME="id" VALUE="{{id}}">
|
<INPUT TYPE="hidden" NAME="id" VALUE="{{id}}">
|
||||||
<CENTER><INPUT TYPE="image" VALUE="Verbind nu!" src="/afbeeldingen/verbind.gif"></INPUT></CENTER>
|
<CENTER><INPUT TYPE="image" VALUE="Verbind nu!" src="/afbeeldingen/verbind.gif"></INPUT></CENTER>
|
||||||
</FORM>
|
</FORM>
|
||||||
|
{% endif %}
|
||||||
</P>
|
</P>
|
||||||
</TR>
|
</TR>
|
||||||
</TABLE>
|
</TABLE>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue