-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_exitvpn_gw.py
More file actions
executable file
·63 lines (49 loc) · 2.15 KB
/
check_exitvpn_gw.py
File metadata and controls
executable file
·63 lines (49 loc) · 2.15 KB
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
#!/usr/bin/env python3
from common import pinit
def check_exitvpn():
'''
Sets the ``BATMAN`` Server Flag and starts/stops ``isc-dhcp-server``,
if some given Hosts can be reached through the `ExitVPN`.
'''
photon, settings = pinit('check_exitvpn', verbose=True)
ping = photon.ping_handler(net_if=settings['exitping']['interface'])
photon.m('sending pings', more=settings['exitping']['targets'])
ping.probe = settings['exitping']['targets']
photon.m('ping results', more=ping.status)
for community in settings['common']['communities']:
interface = settings['batman'][community]['interface']
bandwidth = settings['batman'][community]['bandwidth']
if ping.status['ratio'] <= settings['exitping']['min_ratio']:
photon.m('exitvpn for %s - you are _not_ connected!' % (community))
photon.m(
'removing batman server flag for %s' % (interface),
cmdd=dict(cmd='sudo batctl -m %s gw off' % (interface))
)
if 'start/running' in photon.m(
'check if isc-dhcp-server is running to stop it',
cmdd=dict(cmd='initctl status isc-dhcp-server')
).get('out', ''):
photon.m(
'stopping isc-dhcp-server',
cmdd=dict(cmd='sudo initctl stop isc-dhcp-server')
)
else:
photon.m('exitvpn for %s - you are connected!!' % (community))
photon.m(
'setting batman server flag for %s (bw: %s)' % (
interface, bandwidth
),
cmdd=dict(cmd='sudo batctl -m %s gw server %s' % (
interface, bandwidth
)),
)
if 'stop/waiting' in photon.m(
'check if isc-dhcp-server is not running to start it',
cmdd=dict(cmd='initctl status isc-dhcp-server')
).get('out', ''):
photon.m(
'starting isc-dhcp-server',
cmdd=dict(cmd='sudo initctl start isc-dhcp-server')
)
if __name__ == '__main__':
check_exitvpn()