forked from freifunk-mwu/backend-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnagg_exitvpn_accouts_all.py
executable file
·57 lines (48 loc) · 2.1 KB
/
nagg_exitvpn_accouts_all.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
#!/usr/bin/env python3
def nagg_exitvpn_accouts():
from common import pinit
from datetime import datetime, timedelta
photon, settings = pinit('nagg_exitvpn_accouts', verbose=True)
# initialize the gateway-configs repo ...
photon.git_handler(
settings['configs']['local'],
remote_url=settings['configs']['remote']
)
# .. to load contents from the exitvpn.yaml into the settings
if not photon.settings.load('exitvpn', settings['configs']['exitvpn']):
photon.m(
'could not load exitvpn from git',
more=dict(
exitvpn=settings['configs']['exitvpn']
),
state=True
)
photon.s2m
res=dict(overdue=list(), warning=list(), good=list())
now = datetime.now()
for gateway in sorted(settings['exitvpn']['gateways'].keys()):
if settings['exitvpn']['gateways'][gateway].get('until'):
until = datetime.strptime(settings['exitvpn']['gateways'][gateway]['until'], settings['exitvpn']['conf']['date_format'])
delta = until - now
f = 'overdue' if delta <= timedelta(days=0) else 'warning' if delta <= timedelta(days=settings['exitvpn']['conf']['warndays']) else 'good'
res[f].append({
gateway: settings['exitvpn']['gateways'][gateway]
})
photon.m('results', more=res)
if now.weekday() == settings['exitvpn']['conf']['digestday'] or res['warning']:
punchline = 'Achtung! VPN Account läuft aus' if res['warning'] else 'VPN Wochenbericht'
mail = photon.mail_handler(
to=settings['common']['mailto']['admin'],
cc=settings['common']['mailto']['kontakt'],
sender=settings['common']['mailto']['local'],
subject='photon exitVPN notify',
punchline=punchline,
add_settings=False
)
mail.text = ''
mail.text = res
mail.text = 'Do not forget to update the exitvpn.yaml ( https://github.com/freifunk-mwu/gateway-configs.git )'
mail.text = ''
mail.send
if __name__ == '__main__':
nagg_exitvpn_accouts()