gwinfo: Update to 1.4.2 and add gateway firmware version

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2018-08-28 20:18:16 +02:00
parent 3ee01379dd
commit 424b944254
2 changed files with 100 additions and 6 deletions

81
gwinfo/gwinfofirmware.sh Executable file
View File

@ -0,0 +1,81 @@
#!/bin/sh
#
# Gateway data script for FFF Monitoring
# Copyright Adrian Schmutzler, 2018.
# License GPLv3
#
# designed for GATEWAY FIRMWARE
#
# v1.4.2 - 2018-08-28
# - Fixed IPv4 sed to ignore subnet mask
# - Check for multiple IPv6 addresses
# - GW-Firmware: Ignore wireless devices
# - GW-Firmware: Use eth device from batctl if
# - GW-Firmware: Use only br-mesh for batctl if
# - GW-Firmware: Select fd43 address with ::
# - GW-Firmware: Adjust DHCP to uci
#
# v1.4.1 - 2018-08-25
# - Fixed greps for IPv4/IPv6/dnsmasq
#
# v1.4 - 2018-08-23
# - Transmit internal IPv4/IPv6
# - Transmit DHCP range for dnsmasq
#
# v1.3 - 2018-08-23
# - Support multiple Monitoring URLs
# - Use https by default
# - Changed batctl default path
#
# v1.2.1 - 2018-01-12
# - Added "grep fff" to support L2TP
#
# v1.2 - 2018-01-12
# - Added batctl command and vpnif
#
# v1.1 - 2018-01-12
# - Initial Version
#
# Config
api_urls="https://monitoring.freifunk-franken.de/api/gwinfo" # space-separated list of addresses (api_urls="url1 url2")
batctlpath=/usr/sbin/batctl
hostname="$(uci -q get system.@system[0].hostname)"
statslink="$(uci -q get gateway.@gateway[0].statslink)"
# Code
tmp=$(/bin/mktemp)
echo "{\"hostname\":\"$hostname\",\"stats_page\":\"$statslink\",\"netifs\":[" > $tmp
comma=""
for netif in $(ls /sys/class/net); do
if [ "$netif" = "lo" ] || echo "$netif" | grep "w" ; then # remove wXap, wXmesh, etc.
continue
fi
mac="$(cat "/sys/class/net/$netif/address")"
batctl="$("$batctlpath" -m "$netif" if | grep "eth" | sed -n 's/:.*//p')"
ipv4="$(ip -4 addr show dev br-mesh | grep " 10\." | sed 's/.*\(10\.[^ ]*\/[^ ]*\) .*/\1/')"
ipv6="$(ip -6 addr show dev br-mesh | grep " fd43" | grep '::' | sed 's/.*\(fd43[^ ]*\) .*/\1/')"
[ "$(echo "$ipv6" | wc -l)" = "1" ] || ipv6=""
dhcpstart="$(uci -q get dhcp.mesh.start)"
dhcpend=""
echo "$comma{\"mac\":\"$mac\",\"netif\":\"$netif\",\"vpnif\":\"$batctl\",\"ipv4\":\"$ipv4\",\"ipv6\":\"$ipv6\",\"dhcpstart\":\"$dhcpstart\",\"dhcpend\":\"$dhcpend\"}" >> $tmp
comma=","
done
echo "],\"admins\":[" >> $tmp
comma=""
for admin in $(uci -q get gateway.@gateway[0].admin); do
echo "$comma\"$admin\"" >> $tmp && comma=","
done
echo "]}" >> $tmp
for api_url in $api_urls; do
/usr/bin/curl -k -v -H "Content-type: application/json; charset=UTF-8" -X POST --data-binary @$tmp $api_url
done
/bin/rm "$tmp"

View File

@ -4,6 +4,13 @@
# Copyright Adrian Schmutzler, 2018.
# License GPLv3
#
# designed for GATEWAY SERVER
#
# v1.4.2 - 2018-08-28
# - Fixed IPv4 sed to ignore subnet mask
# - Check for multiple IPv6 addresses
# - Provide experimental support for isc-dhpc-server
#
# v1.4.1 - 2018-08-25
# - Fixed greps for IPv4/IPv6/dnsmasq
#
@ -48,15 +55,21 @@ for netif in $(ls /sys/class/net); do
mac="$(cat "/sys/class/net/$netif/address")"
batctl="$("$batctlpath" -m "$netif" if | grep "fff" | sed -n 's/:.*//p')"
ipv4="$(ip -4 addr show dev "$netif" | grep " 10\." | sed 's/.*\(10\.[^ ]*\) .*/\1/')"
ipv4="$(ip -4 addr show dev "$netif" | grep " 10\." | sed 's/.*\(10\.[^ ]*\/[^ ]*\) .*/\1/')"
ipv6="$(ip -6 addr show dev "$netif" | grep " fd43" | sed 's/.*\(fd43[^ ]*\) .*/\1/')"
[ "$(echo "$ipv6" | wc -l)" = "1" ] || ipv6=""
if [ "$dhcp" = "1" ]; then
dhcpdata="$(ps ax | grep "dnsmasq" | grep "$netif " | sed 's/.*dhcp-range=\([^ ]*\) .*/\1/')"
dhcpstart="$(echo "$dhcpdata" | cut -d',' -f1)"
dhcpend="$(echo "$dhcpdata" | cut -d',' -f2)"
#elif [ "$dhcp" = "2" ]; then
# not implemented
dhcpdata="$(ps ax | grep "dnsmasq" | grep "$netif " | sed 's/.*dhcp-range=\([^ ]*\) .*/\1/')"
dhcpstart="$(echo "$dhcpdata" | cut -d',' -f1)"
dhcpend="$(echo "$dhcpdata" | cut -d',' -f2)"
elif [ "$dhcp" = "2" ]; then
ipv4cut="${ipv4%/*}"
if [ -n "$ipv4cut" ]; then
dhcpdata="$(sed -z 's/.*range \([^;]*\);[^}]*option routers '$ipv4cut'.*/\1/' /etc/dhcp/dhcpd.conf)"
dhcpstart="$(echo "$dhcpdata" | cut -d' ' -f1)"
dhcpend="$(echo "$dhcpdata" | cut -d' ' -f2)"
fi
fi
echo "$comma{\"mac\":\"$mac\",\"netif\":\"$netif\",\"vpnif\":\"$batctl\",\"ipv4\":\"$ipv4\",\"ipv6\":\"$ipv6\",\"dhcpstart\":\"$dhcpstart\",\"dhcpend\":\"$dhcpend\"}" >> $tmp