Make it work, add translations
This commit is contained in:
parent
d437c5ef5c
commit
87662b6966
5 changed files with 154 additions and 65 deletions
175
main.py
175
main.py
|
|
@ -1,21 +1,56 @@
|
|||
import asyncio
|
||||
import pjsua2 as pj
|
||||
from threading import Thread
|
||||
from markupsafe import escape
|
||||
from unificontrol import UnifiClient
|
||||
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
|
||||
from queue import Queue
|
||||
from time import sleep
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
||||
global unifi
|
||||
|
||||
QUEUE = Queue()
|
||||
VISITOR_COUNT_FILE = "visitor_count"
|
||||
SIP = None
|
||||
|
||||
def phone(hostname, username, password):
|
||||
LIB = None
|
||||
|
||||
def call():
|
||||
# Initialize lib
|
||||
LIB = pj.Endpoint()
|
||||
LIB.libCreate()
|
||||
|
||||
ep_cfg = pj.EpConfig()
|
||||
LIB.libInit(ep_cfg)
|
||||
|
||||
transport_cfg = pj.TransportConfig()
|
||||
transport_cfg.port = 5060
|
||||
LIB.transportCreate(pj.PJSIP_TRANSPORT_UDP, transport_cfg)
|
||||
|
||||
LIB.libStart()
|
||||
|
||||
while True:
|
||||
try:
|
||||
id = QUEUE.get(block = True)
|
||||
|
||||
sip_server = str(getenv("SIP_SERVER"))
|
||||
sip_username = str(getenv("SIP_USERNAME"))
|
||||
sip_password = str(getenv("SIP_PASSWORD"))
|
||||
|
||||
# Spawn audio on phone
|
||||
call_phone(sip_server, sip_username, sip_password)
|
||||
|
||||
# authorize guest after a certain amount of time
|
||||
unifi.authorize_guest(id, 1)
|
||||
except:
|
||||
sleep(5)
|
||||
|
||||
def call_phone(hostname, username, password):
|
||||
class MyAccount(pj.Account):
|
||||
def __init__(self):
|
||||
pj.Account.__init__(self)
|
||||
|
|
@ -32,28 +67,7 @@ def phone(hostname, username, password):
|
|||
ci = self.getInfo()
|
||||
print("Call state:", ci.stateText)
|
||||
|
||||
def onCallMediaState(self, prm):
|
||||
ci = self.getInfo()
|
||||
for mi in ci.media:
|
||||
if mi.type == pj.MediaType.AUDIO and mi.status == pj.MediaStatus.ACTIVE:
|
||||
aud_med = self.getMedia(mi.index)
|
||||
aud_med.startTransmit(lib.endpoint.audDevManager().getPlaybackDevMedia())
|
||||
lib.endpoint.audDevManager().getCaptureDevMedia().startTransmit(aud_med)
|
||||
|
||||
# Initialize lib
|
||||
lib = pj.Endpoint()
|
||||
lib.libCreate()
|
||||
|
||||
ep_cfg = pj.EpConfig()
|
||||
lib.libInit(ep_cfg)
|
||||
|
||||
transport_cfg = pj.TransportConfig()
|
||||
transport_cfg.port = 5060
|
||||
lib.transportCreate(pj.PJSIP_TRANSPORT_UDP, transport_cfg)
|
||||
|
||||
lib.libStart()
|
||||
|
||||
# Account config
|
||||
# Account config
|
||||
acc_cfg = pj.AccountConfig()
|
||||
acc_cfg.idUri = f"sip:{username}@{hostname}"
|
||||
acc_cfg.regConfig.registrarUri = f"sip:{hostname}"
|
||||
|
|
@ -63,15 +77,12 @@ def phone(hostname, username, password):
|
|||
acc = MyAccount()
|
||||
acc.create(acc_cfg)
|
||||
|
||||
# Make call
|
||||
# Make call
|
||||
call = MyCall(acc, f"sip:3002@{hostname}")
|
||||
|
||||
# Keep the program running
|
||||
import time
|
||||
time.sleep(30)
|
||||
|
||||
# Clean up
|
||||
lib.libDestroy()
|
||||
# Keep the program running for the duration of the ringtone
|
||||
sleep(18)
|
||||
del call
|
||||
|
||||
|
||||
def main():
|
||||
|
|
@ -86,19 +97,14 @@ def main():
|
|||
USERNAME = str(getenv("USERNAME"))
|
||||
PASSWORD = str(getenv("PASSWORD"))
|
||||
|
||||
SIP_SERVER = str(getenv("SIP_SERVER"))
|
||||
SIP_USERNAME = str(getenv("SIP_USERNAME"))
|
||||
SIP_PASSWORD = str(getenv("SIP_PASSWORD"))
|
||||
|
||||
phone(SIP_SERVER, SIP_USERNAME, SIP_PASSWORD)
|
||||
|
||||
|
||||
cert = get_server_certificate((HOSTNAME, 443))
|
||||
|
||||
global unifi
|
||||
unifi = UnifiClient(host=HOSTNAME,
|
||||
username=USERNAME, password=PASSWORD, cert=cert)
|
||||
|
||||
Thread(target=call).start()
|
||||
|
||||
app.run(host="0.0.0.0", port=80)
|
||||
|
||||
def visitor_count():
|
||||
|
|
@ -116,22 +122,105 @@ def visitor_count():
|
|||
print(f"error {e}")
|
||||
return visitor_count
|
||||
|
||||
LANG_EN = {
|
||||
"Inbellen bij TechInc": "Dialup with TechInc",
|
||||
"TechInc inbel portaal": "TechInc dialup portal",
|
||||
"GRATIS": "FREE",
|
||||
"Gratis": "Free",
|
||||
"gratis": "freely",
|
||||
"Verbind": "Connect for",
|
||||
"met het wereldwijde web": "with the world wide web",
|
||||
"Openen van telefoonlijn...": "Opening the phone line...",
|
||||
"Bellen naar TechInc...": "Calling into TechInc...",
|
||||
"Ontvang verbindingsopties...": "Receiving the connection options...",
|
||||
"Uitzetten van echo onderdrukking...": "Disabling the echo suppression...",
|
||||
"Breedbandspectrum peilen...": "Probing wide-spectrum...",
|
||||
"Equalizer en echo-onderdrukkingstraining...": "Equalizer and echo-suppression training....",
|
||||
"Verbinding met TechInc is gelegd!": "Connection with TechInc has been established!",
|
||||
"openbaar": "publicly",
|
||||
"Welkom, surfer!": "Welcome, surfer!",
|
||||
"Onze snelle telefoon lijn is": "Our fast phone line is",
|
||||
"en": "and",
|
||||
"beschikbaar": "available",
|
||||
"Via onderstaande knop kan je inbellen via je modem.": "With the buttom below you can dial up with your modem",
|
||||
"Inbellen via TechInc heeft de volgende voordelen": "Dial up via TechInc has the following advantages",
|
||||
"Altijd en overal toegang": "Always and everywhere access",
|
||||
"tot het internet via uw telefoonlijn": "to the internet via your telephone line",
|
||||
"Compatibel met alle gangbare 14.4k, 28.8k en 56k modems": "Compatible with all common 14.4k, 28.8k and 56k modems",
|
||||
"Geen installatie nodig": "No installation required!",
|
||||
"werkt direct met Windows 95/98 en Netscape Navigator": "works instantly with Windows 95/98 and Netscape Navigator",
|
||||
"Ondersteuning voor e-mail, nieuwsgroepen en Internet Relay Chat (IRC)": "Support for e-mail, newsgroups and Internet Relay Chat (IRC)",
|
||||
"Beveiligde verbinding via ons eigen TechInc-netwerk": "Secure connecton with our own TechInc network",
|
||||
"u betaalt helemaal niets": "you don't pay anything",
|
||||
"ook niet voor de gespreksduur!": "not even for the duration of the call!",
|
||||
"doe-het-zelf helpdesk voor al uw internetvragen": "do-it-yourself helpdesk for all your internet questions",
|
||||
"Verbind nu!": "Connect now!",
|
||||
"/afbeeldingen/verbind.gif": "/afbeeldingen/connect.gif",
|
||||
"U BENT BEZOEKER NUMMER": "YOU ARE VISITOR NUMBER"
|
||||
}
|
||||
|
||||
LANG_NL = {
|
||||
"Inbellen bij TechInc": "Inbellen bij TechInc",
|
||||
"TechInc inbel portaal": "TechInc inbel portaal",
|
||||
"GRATIS": "GRATIS",
|
||||
"Gratis": "Gratis",
|
||||
"gratis": "gratis",
|
||||
"Verbind": "Verbind",
|
||||
"met het wereldwijde web": "met het wereldwijde web",
|
||||
"Openen van telefoonlijn...": "Openen van telefoonlijn...",
|
||||
"Bellen naar TechInc...": "Bellen naar TechInc...",
|
||||
"Ontvang verbindingsopties...": "Ontvang verbindingsopties...",
|
||||
"Uitzetten van echo onderdrukking...": "Uitzetten van echo onderdrukking...",
|
||||
"Breedbandspectrum peilen...": "Breedbandspectrum peilen...",
|
||||
"Equalizer en echo-onderdrukkingstraining...": "Equalizer en echo-onderdrukkingstraining...",
|
||||
"Verbinding met TechInc is gelegd!": "Verbinding met TechInc is gelegd!",
|
||||
"openbaar": "openbaar",
|
||||
"Welkom, surfer!": "Welkom, surfer!",
|
||||
"Onze snelle telefoon lijn is": "Onze snelle telefoon lijn is",
|
||||
"en": "en",
|
||||
"beschikbaar": "beschikbaar",
|
||||
"Via onderstaande knop kan je inbellen via je modem.": "Via onderstaande knop kan je inbellen via je modem.",
|
||||
"Inbellen via TechInc heeft de volgende voordelen": "Inbellen via TechInc heeft de volgende voordelen",
|
||||
"Altijd en overal toegang": "Altijd en overal toegang",
|
||||
"tot het internet via uw telefoonlijn": "tot het internet via uw telefoonlijn",
|
||||
"Compatibel met alle gangbare 14.4k, 28.8k en 56k modems": "Compatibel met alle gangbare 14.4k, 28.8k en 56k modems",
|
||||
"Geen installatie nodig": "Geen installatie nodig",
|
||||
"werkt direct met Windows 95/98 en Netscape Navigator": "werkt direct met Windows 95/98 en Netscape Navigator",
|
||||
"Ondersteuning voor e-mail, nieuwsgroepen en Internet Relay Chat (IRC)": "Ondersteuning voor e-mail, nieuwsgroepen en Internet Relay Chat (IRC)",
|
||||
"Beveiligde verbinding via ons eigen TechInc-netwerk": "Beveiligde verbinding via ons eigen TechInc-netwerk",
|
||||
"u betaalt helemaal niets": "u betaalt helemaal niets",
|
||||
"ook niet voor de gespreksduur!": "ook niet voor de gespreksduur!",
|
||||
"doe-het-zelf helpdesk voor al uw internetvragen": "doe-het-zelf helpdesk voor al uw internetvragen",
|
||||
"Verbind nu!": "Verbind nu!",
|
||||
"/afbeeldingen/verbind.gif": "/afbeeldingen/verbind.gif",
|
||||
"U BENT BEZOEKER NUMMER": "U BENT BEZOEKER NUMMER"
|
||||
}
|
||||
|
||||
LANG = {
|
||||
'nl': LANG_NL,
|
||||
'en': LANG_EN
|
||||
}
|
||||
|
||||
@app.route('/guest/s/default/', methods=["GET"])
|
||||
def root():
|
||||
supported_languages = ["en", "nl"]
|
||||
lang = request.accept_languages.best_match(supported_languages)
|
||||
|
||||
id = escape(request.args.get('id'))
|
||||
page = render_template("index.html", dialing_up=False, id=id, visitor_count=visitor_count())
|
||||
page = render_template("index.html", dialing_up=False, id=id, lang=LANG[lang], visitor_count=visitor_count())
|
||||
response = Response(page, mimetype="text/html")
|
||||
return response
|
||||
|
||||
@app.route("/dialup", methods=["POST"])
|
||||
def dialup():
|
||||
# Spawn audio on phone
|
||||
# authorize guest after a certain amount of time
|
||||
supported_languages = ["en", "nl"]
|
||||
lang = request.accept_languages.best_match(supported_languages)
|
||||
|
||||
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)
|
||||
|
||||
page = render_template("index.html", dialing_up=True, id=id, lang=LANG[lang], visitor_count=visitor_count())
|
||||
response = Response(page, mimetype="text/html")
|
||||
QUEUE.put(id)
|
||||
return response
|
||||
|
||||
@app.route('/afbeeldingen/<path:path>')
|
||||
|
|
|
|||
BIN
static/connect.gif
Normal file
BIN
static/connect.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
BIN
static/connect.xcf
Normal file
BIN
static/connect.xcf
Normal file
Binary file not shown.
BIN
techinc_dialup.wav
Normal file
BIN
techinc_dialup.wav
Normal file
Binary file not shown.
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Inbellen bij TechInc</TITLE>
|
||||
<TITLE>{{ lang["Inbellen bij TechInc"] }}</TITLE>
|
||||
<SCRIPT type="text/javascript">
|
||||
(function() {
|
||||
var blinks = document.getElementsByTagName('blink');
|
||||
|
|
@ -18,30 +18,30 @@
|
|||
window.onload = function () {
|
||||
var status = document.getElementById('status');
|
||||
console.log(status);
|
||||
status.innerHTML = "Openen van telefoonlijn...";
|
||||
status.innerHTML = "{{lang["Openen van telefoonlijn..."]}}";
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "Bellen naar TechInc...";
|
||||
status.innerHTML = "{{ lang["Bellen naar TechInc..."]}}";
|
||||
}, 768);
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "Ontvang verbindingsopties...";
|
||||
status.innerHTML = "{{ lang["Ontvang verbindingsopties..."] }}";
|
||||
}, 5086);
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "Uitzetten van echo onderdrukking...";
|
||||
status.innerHTML = "{{ lang["Uitzetten van echo onderdrukking..."] }}";
|
||||
}, 8861);
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "Breedbandspectrum peilen...";
|
||||
status.innerHTML = "{{ lang["Breedbandspectrum peilen..."] }}";
|
||||
}, 12123);
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "Equalizer en echo-onderdrukkingstraining...";
|
||||
status.innerHTML = "{{ lang["Equalizer en echo-onderdrukkingstraining..."] }}";
|
||||
}, 13695);
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "Verbinding met TechInc is gelegd!";
|
||||
status.innerHTML = "{{ lang["Verbinding met TechInc is gelegd!"] }}";
|
||||
}, 18326);
|
||||
}
|
||||
{% endif %}
|
||||
|
|
@ -54,7 +54,7 @@
|
|||
<FONT SIZE="+4">
|
||||
<MARQUEE DIRECTION="up" HEIGHT="50px">
|
||||
<CENTER>
|
||||
<B>TechInc inbel portaal</B>
|
||||
<B>{{ lang["TechInc inbel portaal"] }}</B>
|
||||
</CENTER>
|
||||
</MARQUEE>
|
||||
</FONT>
|
||||
|
|
@ -64,22 +64,22 @@
|
|||
<TD>
|
||||
<P>
|
||||
<CENTER>
|
||||
<H2>Verbind <FONT COLOR="red"><BLINK>GRATIS</BLINK></FONT> met het wereldwijde web</H2>
|
||||
<H2>{{ lang["Verbind"] }} <FONT COLOR="red"><BLINK>{{ lang["GRATIS"] }}</BLINK></FONT> {{ lang["met het wereldwijde web"] }}</H2>
|
||||
</CENTER>
|
||||
<P>
|
||||
Welkom, surfer! Onze snelle telefoon lijn is <B><I><FONT COLOR="FUCHSIA">openbaar</FONT></I></B> en <B><I><FONT COLOR="FUCHSIA">gratis</FONT></I></B> beschikbaar.
|
||||
Via onderstaande knop kan je inbellen via je modem.
|
||||
{{ lang["Welkom, surfer!"] }} {{ lang["Onze snelle telefoon lijn is"] }} <B><I><FONT COLOR="FUCHSIA">{{ lang["openbaar"] }}</FONT></I></B> {{lang["en"]}} <B><I><FONT COLOR="FUCHSIA">{{lang["gratis"]}}</FONT></I></B> {{lang["beschikbaar"]}}.
|
||||
{{ lang["Via onderstaande knop kan je inbellen via je modem."]}}
|
||||
</P>
|
||||
<CENTER><H3>Inbellen via TechInc heeft de volgende voordelen</H3></CENTER>
|
||||
<CENTER><H3>{{lang["Inbellen via TechInc heeft de volgende voordelen"]}}</H3></CENTER>
|
||||
<P>
|
||||
<UL>
|
||||
<LI><I>Altijd en overal toegang</I> tot het internet via uw telefoonlijn</LI>
|
||||
<LI>Compatibel met alle gangbare 14.4k, 28.8k en 56k modems</LI>
|
||||
<LI><B>Geen installatie nodig</B> – werkt direct met Windows 95/98 en Netscape Navigator</LI>
|
||||
<LI>Ondersteuning voor e-mail, nieuwsgroepen en Internet Relay Chat (IRC)</LI>
|
||||
<LI>Beveiligde verbinding via ons eigen TechInc-netwerk</LI>
|
||||
<LI><B>Gratis: <FONT COLOR="RED">u betaalt helemaal niets</FONT></B>, ook niet voor de gespreksduur!</LI>
|
||||
<LI><I>24/7</I> doe-het-zelf helpdesk voor al uw internetvragen</LI>
|
||||
<LI><I>{{lang["Altijd en overal toegang"]}}</I> {{lang["tot het internet via uw telefoonlijn"]}}</LI>
|
||||
<LI>{{lang["Compatibel met alle gangbare 14.4k, 28.8k en 56k modems"]}}</LI>
|
||||
<LI><B>{{lang["Geen installatie nodig"]}}</B> – {{lang["werkt direct met Windows 95/98 en Netscape Navigator"]}}</LI>
|
||||
<LI>{{lang["Ondersteuning voor e-mail, nieuwsgroepen en Internet Relay Chat (IRC)"]}}</LI>
|
||||
<LI>{{lang["Beveiligde verbinding via ons eigen TechInc-netwerk"]}}</LI>
|
||||
<LI><B>{{lang["Gratis"]}}: <FONT COLOR="RED">{{lang["u betaalt helemaal niets"]}}</FONT></B>, {{lang["ook niet voor de gespreksduur!"]}}</LI>
|
||||
<LI><I>24/7</I> {{lang["doe-het-zelf helpdesk voor al uw internetvragen"]}}</LI>
|
||||
</UL>
|
||||
</P>
|
||||
<HR>
|
||||
|
|
@ -108,7 +108,7 @@
|
|||
<HR>
|
||||
<P>
|
||||
<CENTER>
|
||||
<H2>U BENT BEZOEKER <FONT COLOR="red"><BLINK>{{visitor_count}}</BLINK></FONT>!</H2>
|
||||
<H2>{{lang["U BENT BEZOEKER NUMMER"]}} <FONT COLOR="red"><BLINK>{{visitor_count}}</BLINK></FONT>!</H2>
|
||||
</CENTER>
|
||||
{% if dialing_up %}
|
||||
<CENTER>
|
||||
|
|
@ -117,7 +117,7 @@
|
|||
{% else %}
|
||||
<FORM METHOD="POST" ACTION="/dialup">
|
||||
<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="{{lang["Verbind nu!"]}}" src="{{lang["/afbeeldingen/verbind.gif"]}}"></INPUT></CENTER>
|
||||
</FORM>
|
||||
{% endif %}
|
||||
</P>
|
||||
|
|
|
|||
Loading…
Reference in a new issue