Compare commits
5 commits
6cd8baf1c7
...
87662b6966
| Author | SHA1 | Date | |
|---|---|---|---|
| 87662b6966 | |||
| d437c5ef5c | |||
| a6ae7c4488 | |||
| ffcc9b3675 | |||
| b439a4a06f |
9 changed files with 236 additions and 32 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "pjproject"]
|
||||
path = pjproject
|
||||
url = https://github.com/pjsip/pjproject.git
|
||||
1
README
Normal file
1
README
Normal file
|
|
@ -0,0 +1 @@
|
|||
Make sure you install pjsua2 from the pjproject submodule. See https://docs.pjsip.org/en/latest/pjsua2/building.html for installation instructions.
|
||||
BIN
dialup techinc.mp3
Normal file
BIN
dialup techinc.mp3
Normal file
Binary file not shown.
193
main.py
193
main.py
|
|
@ -1,17 +1,90 @@
|
|||
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"
|
||||
|
||||
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)
|
||||
|
||||
def onRegState(self, prm):
|
||||
print("Registration state:", prm.code)
|
||||
|
||||
class MyCall(pj.Call):
|
||||
def __init__(self, acc, dest_uri):
|
||||
pj.Call.__init__(self, acc)
|
||||
self.makeCall(dest_uri, pj.CallOpParam(True))
|
||||
|
||||
def onCallState(self, prm):
|
||||
ci = self.getInfo()
|
||||
print("Call state:", ci.stateText)
|
||||
|
||||
# Account config
|
||||
acc_cfg = pj.AccountConfig()
|
||||
acc_cfg.idUri = f"sip:{username}@{hostname}"
|
||||
acc_cfg.regConfig.registrarUri = f"sip:{hostname}"
|
||||
cred = pj.AuthCredInfo("digest", "*", username, 0, password)
|
||||
acc_cfg.sipConfig.authCreds.append(cred)
|
||||
|
||||
acc = MyAccount()
|
||||
acc.create(acc_cfg)
|
||||
|
||||
# Make call
|
||||
call = MyCall(acc, f"sip:3002@{hostname}")
|
||||
|
||||
# Keep the program running for the duration of the ringtone
|
||||
sleep(18)
|
||||
del call
|
||||
|
||||
|
||||
def main():
|
||||
if not os.path.exists(VISITOR_COUNT_FILE):
|
||||
os.mknod(VISITOR_COUNT_FILE)
|
||||
|
|
@ -24,22 +97,22 @@ def main():
|
|||
USERNAME = str(getenv("USERNAME"))
|
||||
PASSWORD = str(getenv("PASSWORD"))
|
||||
|
||||
#cert = get_server_certificate((HOSTNAME, 443))
|
||||
cert = get_server_certificate((HOSTNAME, 443))
|
||||
|
||||
#global unifi
|
||||
#unifi = UnifiClient(host=HOSTNAME,
|
||||
# username=USERNAME, password=PASSWORD, cert=cert)
|
||||
global unifi
|
||||
unifi = UnifiClient(host=HOSTNAME,
|
||||
username=USERNAME, password=PASSWORD, cert=cert)
|
||||
|
||||
app.run(host="0.0.0.0", port=8080)
|
||||
Thread(target=call).start()
|
||||
|
||||
@app.route('/guest/s/default/', methods=["GET"])
|
||||
def root():
|
||||
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 +120,108 @@ def root():
|
|||
visitor_count = visitors
|
||||
except Exception as e:
|
||||
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)
|
||||
|
||||
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, 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 accept():
|
||||
unifi.authorize_guest(id, 1)
|
||||
return "no"
|
||||
def dialup():
|
||||
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, lang=LANG[lang], visitor_count=visitor_count())
|
||||
response = Response(page, mimetype="text/html")
|
||||
QUEUE.put(id)
|
||||
return response
|
||||
|
||||
@app.route('/afbeeldingen/<path:path>')
|
||||
def static_folder(path):
|
||||
|
|
|
|||
1
pjproject
Submodule
1
pjproject
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 796a27a5f2f9a1f704d0a25418f6596af7eab460
|
||||
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');
|
||||
|
|
@ -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 = "{{lang["Openen van telefoonlijn..."]}}";
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "{{ lang["Bellen naar TechInc..."]}}";
|
||||
}, 768);
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "{{ lang["Ontvang verbindingsopties..."] }}";
|
||||
}, 5086);
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "{{ lang["Uitzetten van echo onderdrukking..."] }}";
|
||||
}, 8861);
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "{{ lang["Breedbandspectrum peilen..."] }}";
|
||||
}, 12123);
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "{{ lang["Equalizer en echo-onderdrukkingstraining..."] }}";
|
||||
}, 13695);
|
||||
|
||||
setTimeout(function() {
|
||||
status.innerHTML = "{{ lang["Verbinding met TechInc is gelegd!"] }}";
|
||||
}, 18326);
|
||||
}
|
||||
{% endif %}
|
||||
</SCRIPt>
|
||||
</HEAD>
|
||||
<BODY BACKGROUND="/afbeeldingen/achtergrond.jpg" TEXT="black">
|
||||
|
|
@ -22,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>
|
||||
|
|
@ -32,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>
|
||||
|
|
@ -76,12 +108,18 @@
|
|||
<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>
|
||||
<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}}">
|
||||
<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>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
|
|
|||
Loading…
Reference in a new issue