-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfritz_guest_wifi_voip_toggler.py
64 lines (49 loc) · 1.63 KB
/
fritz_guest_wifi_voip_toggler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from pyVoIP.VoIP import VoIPPhone, InvalidStateError
from fritzconnection.lib.fritzwlan import FritzGuestWLAN
from os import environ as env
from dotenv import load_dotenv
import sys
load_dotenv()
if 'VOIP_HOST' not in env:
print('[error]: VOIP_HOST required')
sys.exit(1)
if 'VOIP_USER' not in env:
print('[error]: VOIP_USER required')
sys.exit(1)
if 'VOIP_PASSWD' not in env:
print('[error]: VOIP_PASSWD required')
sys.exit(1)
if 'VOIP_CLIENT_IP' not in env:
print('[error]: VOIP_CLIENT_IP required')
sys.exit(1)
if 'FRITZ_ADDRESS' not in env:
print('[error]: VOIP_HOST required')
sys.exit(1)
if 'FRITZ_USER' not in env:
print('[error]: VOIP_HOST required')
sys.exit(1)
if 'FRITZ_PASSWD' not in env:
print('[error]: VOIP_HOST required')
sys.exit(1)
def answer(call):
try:
intern = call.request.headers['From']['number'].startswith("**")
if intern:
call.answer()
guest_wlan = FritzGuestWLAN(
address=env['FRITZ_ADDRESS'], user=env['FRITZ_USER'], password=env['FRITZ_PASSWD'])
if guest_wlan.is_enabled:
guest_wlan.disable()
print('Guest WLAN disabled')
else:
guest_wlan.enable()
print('Guest WLAN enabled')
call.hangup()
except InvalidStateError:
pass
if __name__ == "__main__":
phone = VoIPPhone(env['VOIP_HOST'], 5060, env['VOIP_USER'],
env['VOIP_PASSWD'], callCallback=answer, myIP=env['VOIP_CLIENT_IP'])
phone.start()
input('Press enter to disable the phone')
phone.stop()