Fastd-Status und ffgate-check eingebaut, sowie ein mini Installationsscript
parent
cfbc7dc177
commit
e90f08538e
|
@ -0,0 +1 @@
|
|||
*~
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Informationen aus dem fastd-Socket anzeigen.
|
||||
Voraussetzung ist natürlich, daß dieser über die fastd-Konfiguration
|
||||
eingeschaltet ist.
|
||||
Programm von Freifunk Pinneberg / Havelock
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import socket
|
||||
import json
|
||||
|
||||
def get_fastd_data(sockfile):
|
||||
# fastd-Socket auslesen, liefert ein JSON-Objekt
|
||||
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
try:
|
||||
client.connect(sockfile)
|
||||
except socket.error, msg:
|
||||
print >>sys.stderr, msg
|
||||
sys.exit(1)
|
||||
data = json.loads(client.makefile('r').read())
|
||||
client.close()
|
||||
return data
|
||||
|
||||
def get_gate_macs():
|
||||
# Ermitteln der (sichtbaten) Gateways
|
||||
with open('/sys/kernel/debug/batman_adv/bat0/gateways') as f:
|
||||
lines = f.readlines()
|
||||
return set([gw[3:20] for gw in lines[1:]])
|
||||
|
||||
def main():
|
||||
data = get_fastd_data("/var/run/fastd/ffpi.sock")
|
||||
gw_macs = get_gate_macs()
|
||||
npeers = 0
|
||||
ngates = 0
|
||||
for key, peer in data['peers'].iteritems():
|
||||
if peer['connection']:
|
||||
if set(peer['connection']['mac_addresses']) & gw_macs:
|
||||
print "Gate %s (%s) connected as %s..." % (peer['name'], peer['connection']['mac_addresses'][0], key[:16])
|
||||
ngates += 1
|
||||
else:
|
||||
print "Peer %s (%s) connected as %s..." % (peer['name'], peer['connection']['mac_addresses'][0], key[:16])
|
||||
npeers += 1
|
||||
print "%d peers total, %d gateways and %d peers currently connected" % (len(data['peers']), ngates, npeers)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,73 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# ffgate-check - WIP
|
||||
#
|
||||
# Ziel: Prüfen, ob ein Exit-VPN funktionsfähig ist, bei
|
||||
# einem Problem schwenken zu einem anderen Exit und im
|
||||
# schlimmsten Fall deaktivieren der Gatewayfunktion.
|
||||
#
|
||||
# siehe auch: https://wiki.luebeck.freifunk.net/gatewayconfig
|
||||
#
|
||||
# TODO
|
||||
# - Umsetzen nach python
|
||||
# - Absetzen einer Meldung an Zabbix
|
||||
# - Auswerten einer zentralen Community-Konfigurationsdatei
|
||||
#
|
||||
VPNCONF=$(grep -e "^AUTOSTART=" /etc/default/openvpn)
|
||||
INTERFACE=$(sed -e 's/^"//' -e 's/"$//' <<< ${VPNCONF#*=})
|
||||
TESTIP=217.172.186.141 # gate05
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
if [ ! $UID -eq 0 ]; then
|
||||
log_failure_msg "This script must be run as user root!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prüfe ob OpenVPN läuft
|
||||
log_daemon_msg "OpenVPN process"
|
||||
if [ `pgrep openvpn` ]; then
|
||||
log_progress_msg " running"
|
||||
log_end_msg 0
|
||||
else
|
||||
log_progress_msg " not running"
|
||||
log_end_msg 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# prüfe, ob das angegebene Interface überhaupt existiert
|
||||
log_daemon_msg "Interface $INTERFACE"
|
||||
if [ -d "/sys/class/net/$INTERFACE" ]; then
|
||||
log_progress_msg " exists"
|
||||
log_end_msg 0
|
||||
else
|
||||
log_progress_msg " does not exist"
|
||||
log_end_msg 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prüfe, ob die Firewall auf das korrekte VPN-Interface eingestellt ist
|
||||
log_daemon_msg "Firewall-Interface"
|
||||
NATIF=$(iptables -t nat -vnL | grep MASQUERADE | awk '{$1=$1};1' | cut -d' ' -f 7)
|
||||
if test "$NATIF" == "$INTERFACE" ; then
|
||||
log_progress_msg " is correct"
|
||||
log_end_msg 0
|
||||
else
|
||||
log_progress_msg " is wrong ($NATIF)"
|
||||
log_end_msg 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prüfe ob ein externes Ping durch das Interface funktioniert
|
||||
log_daemon_msg "Tunnel $INTERFACE"
|
||||
ping -q -I $INTERFACE $TESTIP -c 4 -i 1 -W 5 >/dev/null 2>&1
|
||||
if test $? -eq 0; then
|
||||
log_progress_msg " is up"
|
||||
log_end_msg 0
|
||||
else
|
||||
log_progress_msg " is down"
|
||||
log_end_msg 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
install fastd-status.py /usr/local/bin
|
||||
install ffgate-check /usr/local/bin
|
||||
install alfred-announce.py /usr/local/bin
|
||||
|
Loading…
Reference in New Issue